@@ -14,21 +14,24 @@ test_that("Mathur's algorithm returns reasonable values even with bad slopes", {
1414
1515 f <- function (x ) ifelse(x %in% 1 : 2 , x ^ 2 , NA )
1616 expect_warning(m <- step.M(f , 1 , cores = 1 ), " <3 finite function values" )
17+ expect_identical(m $ exitcode , 3L )
1718})
1819
1920test_that(" Mathur's algorithm may return unreasonable values" , {
2021 f <- function (x ) x ^ 3 + 1 / x # Produces wildly wrong results due to the shape of the error plot
2122 expect_gt(plot(step.M(f , 1 , cores = 1 ))$ par , 0.01 )
2223})
2324
25+ test_that(" Mathur's algorithm returns expected non-zero exit codes" , {
26+ # Noisy right branch
27+ expect_identical(suppressWarnings(step.M(function (x ) x ^ 2 , x = 1e-8 )$ exitcode ), 2L )
28+ # No branches at all
29+ expect_identical(suppressWarnings(step.M(function (x ) x ^ 2 , x = 0 )$ exitcode ), 2L )
30+ })
31+
2432test_that(" Parallelisation in Mathur's algorithm works" , {
2533 expect_identical(step.M(sin , 1 , cores = 1 ), step.M(sin , 1 , cores = 2 ))
2634 clus <- parallel :: makePSOCKcluster(2 )
2735 expect_identical(step.M(sin , 1 , cores = 1 ), step.M(sin , 1 , cl = clus ))
2836 parallel :: stopCluster(clus )
29-
30- # Testing a slow function
31- # f <- function(x) {Sys.sleep(0.1); sin(x)}
32- # system.time(step.M(f, 1))
33- # system.time(step.M(f, 1, cores = 12))
3437})
0 commit comments