Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Nov 17, 2023
1 parent cf257e0 commit f752cb6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions tests/testthat/test-delays.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test_that("generation times can be specified in different ways", {
generation_time = generation_time_opts(dist_spec(mean = 3, sd = 1, max = 4)),
params = delay_params
), digits = 2),
c(0.02, 0.11, 0.22, 0.30, 0.35)
c(0.01, 0.08, 0.20, 0.32, 0.40)
)
})

Expand All @@ -49,7 +49,7 @@ test_that("delay parameters can be specified in different ways", {
delays = delay_opts(dist_spec(mean = 3, sd = 1, max = 4)),
params = delay_params
), digits = 2), n = -2),
c(0.02, 0.11, 0.22, 0.30, 0.35)
c(0.01, 0.08, 0.20, 0.32, 0.40)
)
})

Expand All @@ -59,7 +59,7 @@ test_that("truncation parameters can be specified in different ways", {
truncation = trunc_opts(dist = dist_spec(mean = 3, sd = 1, max = 4)),
params = delay_params
), digits = 2), n = -2),
c(0.02, 0.11, 0.22, 0.30, 0.35)
c(0.01, 0.08, 0.20, 0.32, 0.40)
)
})

Expand Down
15 changes: 7 additions & 8 deletions tests/testthat/test-dist_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("dist_spec returns correct output for fixed lognormal distribution", {
as.vector(round(result$np_pmf, 2)),
c(0.00, 0.00, 0.00, 0.00, 0.01, 0.01, 0.02, 0.03,
0.03, 0.04, 0.05, 0.06, 0.07, 0.07, 0.08, 0.09,
0.10, 0.10, 0.11, 0.12)
0.10, 0.11, 0.11, 0.12)
)
})

Expand Down Expand Up @@ -40,7 +40,7 @@ test_that("dist_spec returns correct output for fixed distribution", {
as.vector(round(result$np_pmf, 2)),
c(0.00, 0.00, 0.00, 0.00, 0.01, 0.01, 0.02, 0.03,
0.03, 0.04, 0.05, 0.06, 0.07, 0.07, 0.08, 0.09,
0.10, 0.10, 0.11, 0.12)
0.10, 0.11, 0.11, 0.12)
)
})

Expand Down Expand Up @@ -86,7 +86,7 @@ test_that("+.dist_spec returns correct output for sum of two fixed distributions
expect_equal(result$n, 1)
expect_equal(result$n_p, 0)
expect_equal(result$n_np, 1)
expect_equal(result$np_pmf_length, 30)
expect_equal(result$np_pmf_length, 31)
})

test_that("+.dist_spec returns correct output for sum of two nonparametric distributions", {
Expand Down Expand Up @@ -146,8 +146,7 @@ test_that("mean.dist_spec returns correct output for fixed lognormal distributio
max = 19, distribution = "lognormal"
)
result <- EpiNow2:::mean.dist_spec(lognormal)
expect_equal(result, 2.49, tolerance = 0.01) # here we can see the bias from
# using this kind of discretisation approach
expect_equal(result, 3.0, tolerance = 0.01)
})

test_that("mean.dist_spec returns correct output for uncertain gamma distribution", {
Expand All @@ -160,13 +159,13 @@ test_that("mean.dist_spec returns correct output for sum of two distributions",
lognormal <- dist_spec(mean = 1, sd = 1, max = 19, distribution = "lognormal")
gamma <- dist_spec(mean = 3, sd = 2, max = 19, distribution = "gamma")
result <- EpiNow2:::mean.dist_spec(lognormal + gamma)
expect_equal(result, c(5.84), tolerance = 0.001)
expect_equal(result, c(6.82), tolerance = 0.001)
})

test_that("print.dist_spec correctly prints the parameters of the fixed lognormal", {
lognormal <- dist_spec(mean = 1.5, sd = 0.5, max = 19, distribution = "lognormal")

expect_output(print(lognormal), "\\n Fixed distribution with PMF \\[0\\.0014 0\\.052 0\\.16 0\\.2 0\\.18 0\\.13 0\\.094 0\\.063 0\\.042 0\\.027 0\\.018 0\\.012 0\\.0079 0\\.0052 0\\.0035 0\\.0024 0\\.0016 0\\.0011 0\\.00078 0\\.00055\\]\\n")
expect_output(print(lognormal), "\\n Fixed distribution with PMF \\[0\\.00068 0\\.027 0\\.11 0\\.18 0\\.19 0\\.16 0\\.11 0\\.078 0\\.052 0\\.035 0\\.023 0\\.015 0\\.0099 0\\.0065 0\\.0044 0\\.003 0\\.002 0\\.0014 0\\.00095 0\\.00066\\]\\n")
})

test_that("print.dist_spec correctly prints the parameters of the uncertain gamma", {
Expand Down Expand Up @@ -195,7 +194,7 @@ test_that("print.dist_spec correctly prints the parameters of a combination of d
gamma <- dist_spec(mean = 3, sd = 2, mean_sd = 0.5, sd_sd = 0.5, max = 19, distribution = "gamma")
combined <- lognormal + gamma

expect_output(print(combined), "Combination of delay distributions:\\n Fixed distribution with PMF \\[0\\.0014 0\\.052 0\\.16 0\\.2 0\\.18 0\\.13 0\\.094 0\\.063 0\\.042 0\\.027 0\\.018 0\\.012 0\\.0079 0\\.0052 0\\.0035 0\\.0024 0\\.0016 0\\.0011 0\\.00078 0\\.00055\\]\\n Uncertain gamma distribution with \\(untruncated\\) mean 3 \\(SD 0\\.5\\) and SD 2 \\(SD 0\\.5\\)\\n")
expect_output(print(combined), "\\nCombination of delay distributions:\\n Fixed distribution with PMF \\[0\\.00068 0\\.027 0\\.11 0\\.18 0\\.19 0\\.16 0\\.11 0\\.078 0\\.052 0\\.035 0\\.023 0\\.015 0\\.0099 0\\.0065 0\\.0044 0\\.003 0\\.002 0\\.0014 0\\.00095 0\\.00066\\]\\n Uncertain gamma distribution with \\(untruncated\\) mean 3 \\(SD 0\\.5\\) and SD 2 \\(SD 0\\.5\\)\\n")
})

test_that("plot.dist_spec returns a ggplot object", {
Expand Down

0 comments on commit f752cb6

Please sign in to comment.