Skip to content

Commit

Permalink
Add tests for simulate_summary()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmbaazam authored and sbfnk committed Jan 30, 2024
1 parent 835252f commit 80cec06
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/testthat/_snaps/simulate.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# simulate_summary is numerically correct

Code
sim_summary_small_pop
Output
`epichains_summary` object
[1] 1 1 1 1 1 2 1 1 1 1
Simulated tree lengths:
Max: 2
Min: 1

# simulate_chains produces expected snapshots

Code
Expand Down
34 changes: 34 additions & 0 deletions tests/testthat/test-simulate.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ test_that("simulate_summary throws errors", {
)
})

test_that("simulate_summary is numerically correct",{
# Run a simulation in a small population so that
# we encounter the case where we have more potential offspring than
# susceptible individuals
set.seed(32) # this seed gives a sizeable outcome
sim_summary_small_pop <- simulate_summary(
pop = 11,
percent_immune = 0,
index_cases = 10,
offspring_dist = "pois",
statistic = "length",
lambda = 2
)
#' summarise the results
sim_summary_summarised <- summary(sim_summary_small_pop)
expect_identical(
as.vector(sim_summary_small_pop),
c(1, 1, 1, 1, 1, 2, 1, 1, 1, 1)
)
expect_identical(
length(sim_summary_small_pop),
as.integer(sim_summary_summarised$index_cases)
)
expect_identical(
sim_summary_summarised$max_stat,
2
)
expect_identical(
sim_summary_summarised$min_stat,
1
)
expect_snapshot(sim_summary_small_pop)
})

test_that("simulate_chains is numerically correct", {
set.seed(32) # this seed gives a sizeable outcome
sim_chains_small_susc <- simulate_chains(
Expand Down

0 comments on commit 80cec06

Please sign in to comment.