Skip to content

Commit

Permalink
make long-running tests quicker
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Oct 23, 2024
1 parent 873b6d8 commit caa4e95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions tests/testthat/test-non-numeric-pids.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ test_that("Using numeric and non-numeric pids gives the same answer", {
expect_equal(stan_data, stan_data_new, ignore_attr = TRUE)

fit <- mod$fit(parallel_chains = 4,
iter_warmup = 50,
iter_sampling = 100,
iter_warmup = 10,
iter_sampling = 40,
seed = 100)

fit_new <- mod_new$fit(parallel_chains = 4,
iter_warmup = 50,
iter_sampling = 100,
iter_warmup = 10,
iter_sampling = 40,
seed = 100)

expect_equal(fit$draws(), fit_new$draws(), ignore_attr = TRUE)
Expand Down
6 changes: 1 addition & 5 deletions tests/testthat/test-plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ test_that("Can plot prior predictions from model", {
})

test_that("Prior predictions from model are the same", {
skip_on_ci()
data <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
priors <- biokinetics_priors(mu_values = c(4.1, 11, 65, 0.2, -0.01, 0.01),
sigma_values = c(2.0, 2.0, 3.0, 0.01, 0.01, 0.001))
Expand All @@ -41,7 +40,6 @@ test_that("Prior predictions from model are the same", {
})

test_that("Can plot input data", {
skip_on_ci()
data <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod <- biokinetics$new(data = data)
plot <- mod$plot_model_inputs()
Expand All @@ -57,7 +55,6 @@ mock_model <- function(name, package) {
}

test_that("Summarised and un-summarised population trajectories give same plots", {
skip_on_ci()
# note that this is using a pre-fitted model with very few iterations, so the
# fits won't look very good
local_mocked_bindings(
Expand All @@ -69,11 +66,10 @@ test_that("Summarised and un-summarised population trajectories give same plots"
trajectories <- mod$simulate_population_trajectories(summarise = TRUE)
unsummarised_trajectories <- mod$simulate_population_trajectories(summarise = FALSE)
vdiffr::expect_doppelganger("populationtrajectories", plot(trajectories))
# vdiffr::expect_doppelganger("populationtrajectories", plot(unsummarised_trajectories))
vdiffr::expect_doppelganger("populationtrajectories", plot(unsummarised_trajectories))
})

test_that("Can plot population trajectories with data", {
skip_on_ci()
local_mocked_bindings(
stan_package_model = mock_model, .package = "instantiate"
)
Expand Down
9 changes: 5 additions & 4 deletions tests/testthat/test-relative-dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ test_that("Using relative and absolute dates gives the same answer", {
dat_absolute <- data.table::fread(system.file("delta_full.rds", package = "epikinetics"))
mod_absolute <- biokinetics$new(data = dat_absolute, covariate_formula = ~0 + infection_history)
delta_absolute <- mod_absolute$fit(parallel_chains = 4,
iter_warmup = 50,
iter_warmup = 10,
iter_sampling = 100,
seed = 100)

set.seed(1)
trajectories_absolute <- mod_absolute$simulate_individual_trajectories()
trajectories_absolute <- mod_absolute$simulate_individual_trajectories(summarise = FALSE)

dat_relative <- data.table::fread(test_path("testdata", "delta_full_relative.rds"))
mod_relative <- biokinetics$new(data = dat_relative, covariate_formula = ~0 + infection_history)
delta_relative <- mod_relative$fit(parallel_chains = 4,
iter_warmup = 50,
iter_warmup = 10,
iter_sampling = 100,
seed = 100)

set.seed(1)
trajectories_relative <- mod_relative$simulate_individual_trajectories()
trajectories_relative <- mod_relative$simulate_individual_trajectories(summarise = FALSE)

# convert relative days to absolute
min_date <- min(dat_absolute$day)
trajectories_relative$calendar_day <- min_date + trajectories_relative$calendar_day
trajectories_relative$exposure_day <- min_date + trajectories_relative$exposure_day

expect_equal(trajectories_relative, trajectories_absolute)

Expand Down

0 comments on commit caa4e95

Please sign in to comment.