Skip to content

Commit

Permalink
added unit tests for .clean_epidist_params and create_epidist_prob_di…
Browse files Browse the repository at this point in the history
…st for exponential dist
  • Loading branch information
joshwlambert committed Jun 10, 2024
1 parent fd93fe4 commit 63b304d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testthat/test-create_epidist_prob_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ test_that("create_epidist_prob_dist works for poisson", {
)
})

test_that("create_epidist_prob_dist works for exponential", {
res <- create_epidist_prob_dist(
prob_dist = "exp",
prob_dist_params = c(rate = 2),
discretise = FALSE,
truncation = NA
)

expect_s3_class(res, "distribution")
expect_identical(family(res), "exponential")
expect_identical(
distributional::parameters(res),
data.frame(rate = 2)
)
})

test_that("create_epidist_prob_dist works for discrete gamma", {
res <- create_epidist_prob_dist(
prob_dist = "gamma",
Expand Down
30 changes: 30 additions & 0 deletions tests/testthat/test-epidist_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,36 @@ test_that(".clean_epidist_params fails when pois parameters are incorrect", {
)
})

test_that(".clean_epidist_params works as expected for exp", {
params <- .clean_epidist_params(
prob_dist = "exp",
prob_dist_params = c(rate = 2)
)
expect_identical(params, c(rate = 2))

params <- .clean_epidist_params(
prob_dist = "exp",
prob_dist_params = c(lambda = 2)
)
expect_identical(params, c(rate = 2))

params <- .clean_epidist_params(
prob_dist = "exp",
prob_dist_params = c(mean = 0.5)
)
expect_identical(params, c(rate = 2))
})

test_that(".clean_epidist_params fails when exp parameters are incorrect", {
expect_error(
.clean_epidist_params(
prob_dist = "exp",
prob_dist_params = c(means = 1)
),
regexp = "Invalid parameterisation for exp distribution"
)
})

test_that(".clean_epidist_params fails as expected", {
expect_error(
.clean_epidist_params(
Expand Down

0 comments on commit 63b304d

Please sign in to comment.