# Homework 04 helper function # =========================== library(stringr) # load sample data -- variable ..data.vec.. load("data_sample.RData") # test the function # - implicit value, i.e second biggest try(result1 <- xMax(..data.vec..)) # - biggest value try(result2 <- xMax(..data.vec.., 1L)) # - tenth biggest value try(result3 <- xMax(..data.vec.., 10L)) # - out of bound try(xMax(..data.vec.., 0L)) result4 <- str_detect(geterrmessage(), "n is out of bounds") try(xMax(..data.vec.., length(..data.vec..) + 1L)) result4 <- result4 & str_detect(geterrmessage(), "n is out of bounds") # - isn't one number try(xMax(..data.vec.., 1:3)) result5 <- str_detect(geterrmessage(), "n isn't one round number") try(xMax(..data.vec.., "ahoj")) result5 <- result5 & str_detect(geterrmessage(), "n isn't one round number") # - isn't round number try(xMax(..data.vec.., 1.5)) result6 <- str_detect(geterrmessage(), "n isn't one round number") # - v isn't unique try(xMax(c(..data.vec.., ..data.vec..[1]))) result7 <- str_detect(geterrmessage(), "v doesn't have unique values")