Skip to content

Commit

Permalink
add a test for the specific transform data method
Browse files Browse the repository at this point in the history
  • Loading branch information
seabbs committed Dec 2, 2024
1 parent 6c529f1 commit 9c0d9a2
Showing 1 changed file with 64 additions and 5 deletions.
69 changes: 64 additions & 5 deletions tests/testthat/test-marginal_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ test_that("as_epidist_marginal_model.epidist_linelist_data with default settings
expect_s3_class(prep_marginal_obs, "epidist_marginal_model")
})

test_that("as_epidist_marginal_model.epidist_linelist_data when passed incorrect inputs", { # nolint: line_length_linter.
test_that("as_epidist_marginal_model.epidist_linelist_data errors when passed incorrect inputs", { # nolint: line_length_linter.
expect_error(as_epidist_marginal_model(list()))
expect_error(as_epidist_marginal_model(sim_obs[, 1]))
})

# Make this data available for other tests
family_lognormal <- epidist_family(
prep_marginal_obs,
family = brms::lognormal()
)
family_lognormal <- epidist_family(prep_marginal_obs, family = lognormal())

test_that("is_epidist_marginal_model returns TRUE for correct input", { # nolint: line_length_linter.
expect_true(is_epidist_marginal_model(prep_marginal_obs))
Expand Down Expand Up @@ -46,3 +43,65 @@ test_that("assert_epidist.epidist_marginal_model returns FALSE for incorrect inp
assert_epidist(x)
})
})

test_that("epidist_stancode.epidist_marginal_model produces valid stanvars", { # nolint: line_length_linter.
epidist_family <- epidist_family(prep_marginal_obs)
epidist_formula <- epidist_formula(
prep_marginal_obs, epidist_family,
formula = bf(mu ~ 1)
)
stancode <- epidist_stancode(
prep_marginal_obs,
family = epidist_family, formula = epidist_formula
)
expect_s3_class(stancode, "stanvars")
})

test_that("epidist_transform_data_model.epidist_marginal_model correctly transforms data and messages", { # nolint: line_length_linter.
family <- epidist_family(prep_marginal_obs, family = lognormal())
formula <- epidist_formula(
prep_marginal_obs,
formula = bf(mu ~ 1),
family = family
)
expect_no_message(
expect_message(
expect_message(
expect_message(
epidist_transform_data_model(
prep_marginal_obs,
family = family,
formula = formula
),
"Reduced from 500 to 144 rows."
),
"Data summarised by unique combinations of:"
),
"Model variables"
)
)

family <- epidist_family(prep_marginal_obs, family = lognormal())
formula <- epidist_formula(
prep_marginal_obs,
formula = bf(mu ~ 1 + ptime_lwr),
family = family
)
expect_message(
expect_message(
expect_message(
expect_message(
epidist_transform_data_model(
prep_marginal_obs,
family = family,
formula = formula
),
"Reduced from 500 to 144 rows."
),
"Data summarised by unique combinations of:"
),
"Model variables"
),
"ptime_lwr"
)
})

0 comments on commit 9c0d9a2

Please sign in to comment.