aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_parboot.R
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat/test_parboot.R')
-rw-r--r--tests/testthat/test_parboot.R44
1 files changed, 39 insertions, 5 deletions
diff --git a/tests/testthat/test_parboot.R b/tests/testthat/test_parboot.R
index c3ece25..af62658 100644
--- a/tests/testthat/test_parboot.R
+++ b/tests/testthat/test_parboot.R
@@ -32,15 +32,49 @@ test_that("parboot works", {
dev.off()
expect_equal(pl, NULL)
- # check that report works
- rep_output <- capture.output(parboot(fm, fitstats, nsim=3, report=TRUE))
- expect_equal(substr(rep_output[1], 1,2), "t0")
+ # check that report argument gives warning
+ expect_warning(parboot(fm, fitstats, nsim=3, report=TRUE))
})
test_that("parboot works in parallel",{
skip_on_cran()
skip_on_ci()
# check parallel
- pb <- parboot(fm, nsim=101, parallel=TRUE, ncores=2)
- expect_equal(length(pb@t.star), 101)
+ pb <- parboot(fm, nsim=10, parallel=TRUE, ncores=2)
+ expect_equal(length(pb@t.star), 10)
+})
+
+test_that("parboot handles failing model fits", {
+
+ fail_func <- function(x){
+ rand <- rnorm(1)
+ if(rand > 0.5){
+ stop("fail")
+ }
+ return(rand)
+ }
+
+ set.seed(123)
+ expect_warning(pb <- parboot(fm, nsim=20, statistic=fail_func))
+ expect_equal(nrow(pb@t.star), 13)
+
+ expect_warning(pb <- parboot(fm, nsim=20, statistic=fail_func, parallel=TRUE))
+ expect_true(nrow(pb@t.star) < 20)
+
+})
+
+test_that("parboot handles statistic functions with additional arguments", {
+
+ opt_func <- function(x, y){
+ res <- mean(residuals(x), na.rm=TRUE)
+ c(res=res, y=y)
+ }
+
+ pb <- parboot(fm, nsim=10, statistic=opt_func, y=0.1)
+ expect_equal(colnames(pb@t.star), c("res", "y"))
+ expect_true(all(pb@t.star[,"y"]==0.1))
+
+ pb <- parboot(fm, nsim=10, statistic=opt_func, y=0.1, parallel=TRUE)
+ expect_equal(colnames(pb@t.star), c("res", "y"))
+ expect_true(all(pb@t.star[,"y"]==0.1))
})