Skip to content

Commit

Permalink
Pass arguments to stan_opts as list in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Nov 13, 2023
1 parent 5410759 commit db0bfce
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/testthat/test-estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ reported_cases <- EpiNow2::example_confirmed[1:30]
default_estimate_infections <- function(..., add_stan = list(), delay = TRUE) {
futile.logger::flog.threshold("FATAL")

def_stan <- stan_opts(
def_stan <- list(
chains = 2, warmup = 50, samples = 50,
control = list(adapt_delta = 0.8)
)
stan_args <- def_stan[setdiff(names(def_stan), names(add_stan))]
stan_args <- do.call(stan_opts, c(stan_args, add_stan))
def_stan <- modifyList(def_stan, add_stan)
stan_args <- do.call(stan_opts, def_stan)

suppressWarnings(estimate_infections(...,
generation_time = generation_time_opts(example_generation_time),
Expand Down Expand Up @@ -78,31 +78,31 @@ test_that("estimate_infections fails as expected when given a very short timeout
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = stan_opts(future = TRUE, max_execution_time = 1)
add_stan = list(future = TRUE, max_execution_time = 1)
))), "all chains failed")
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = stan_opts(future = FALSE, max_execution_time = 1)
add_stan = list(future = FALSE, max_execution_time = 1)
))), "timed out")
})


test_that("estimate_infections works as expected with failing chains", {
skip_on_cran()
test_estimate_infections(reported_cases,
add_stan = stan_opts(
add_stan = list(
chains = 4,
stuck_chains = 2, future = TRUE,
control = list(adapt_delta = 0.8)
)
)

expect_error(default_estimate_infections(reported_cases,
add_stan = stan_opts(chains = 4, stuck_chains = 1)
add_stan = list(chains = 4, stuck_chains = 1)
))
expect_error(default_estimate_infections(reported_cases,
add_stan = stan_opts(
add_stan = list(
chains = 4,
stuck_chains = 3,
future = TRUE
Expand Down

0 comments on commit db0bfce

Please sign in to comment.