Skip to content

Only set seeds in testing when needed. #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update snapshots
  • Loading branch information
sbfnk authored and seabbs committed Mar 1, 2024
commit 3d0f86466dbfb10e1f9b3ec76373ca901bc7fa82
56 changes: 28 additions & 28 deletions tests/testthat/_snaps/simulate-infections.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
12: infections 2023-01-12 117.41367
13: infections 2023-01-13 93.93093
14: infections 2023-01-14 75.14475
15: reported_cases 2023-01-01 128.00000
16: reported_cases 2023-01-02 151.00000
17: reported_cases 2023-01-03 145.00000
18: reported_cases 2023-01-04 188.00000
19: reported_cases 2023-01-05 252.00000
20: reported_cases 2023-01-06 276.00000
21: reported_cases 2023-01-07 371.00000
22: reported_cases 2023-01-08 273.00000
23: reported_cases 2023-01-09 234.00000
24: reported_cases 2023-01-10 192.00000
25: reported_cases 2023-01-11 157.00000
26: reported_cases 2023-01-12 120.00000
27: reported_cases 2023-01-13 78.00000
28: reported_cases 2023-01-14 63.00000
15: reported_cases 2023-01-01 125.00000
16: reported_cases 2023-01-02 135.00000
17: reported_cases 2023-01-03 195.00000
18: reported_cases 2023-01-04 224.00000
19: reported_cases 2023-01-05 253.00000
20: reported_cases 2023-01-06 328.00000
21: reported_cases 2023-01-07 364.00000
22: reported_cases 2023-01-08 278.00000
23: reported_cases 2023-01-09 206.00000
24: reported_cases 2023-01-10 169.00000
25: reported_cases 2023-01-11 144.00000
26: reported_cases 2023-01-12 109.00000
27: reported_cases 2023-01-13 80.00000
28: reported_cases 2023-01-14 95.00000
variable date value

# simulate_infections works as expected with additional parameters
Expand All @@ -50,19 +50,19 @@
12: infections 2023-01-12 190.8991
13: infections 2023-01-13 180.8132
14: infections 2023-01-14 171.1484
15: reported_cases 2023-01-01 425.0000
16: reported_cases 2023-01-02 335.0000
17: reported_cases 2023-01-03 376.0000
18: reported_cases 2023-01-04 250.0000
19: reported_cases 2023-01-05 301.0000
20: reported_cases 2023-01-06 275.0000
21: reported_cases 2023-01-07 844.0000
22: reported_cases 2023-01-08 235.0000
23: reported_cases 2023-01-09 205.0000
24: reported_cases 2023-01-10 251.0000
25: reported_cases 2023-01-11 239.0000
26: reported_cases 2023-01-12 80.0000
27: reported_cases 2023-01-13 128.0000
28: reported_cases 2023-01-14 276.0000
15: reported_cases 2023-01-01 155.0000
16: reported_cases 2023-01-02 563.0000
17: reported_cases 2023-01-03 146.0000
18: reported_cases 2023-01-04 644.0000
19: reported_cases 2023-01-05 282.0000
20: reported_cases 2023-01-06 473.0000
21: reported_cases 2023-01-07 193.0000
22: reported_cases 2023-01-08 262.0000
23: reported_cases 2023-01-09 19.0000
24: reported_cases 2023-01-10 277.0000
25: reported_cases 2023-01-11 177.0000
26: reported_cases 2023-01-12 273.0000
27: reported_cases 2023-01-13 97.0000
28: reported_cases 2023-01-14 265.0000
variable date value

4 changes: 4 additions & 0 deletions tests/testthat/test-simulate-infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@ test_simulate_infections <- function(obs = obs_opts(family = "poisson"), ...) {
}

test_that("simulate_infections works as expected with standard parameters", {
set.seed(123)
sim <- test_simulate_infections()
expect_equal(nrow(sim), 2 * nrow(R))
expect_snapshot_output(sim)
set.seed(Sys.time())
})

test_that("simulate_infections works as expected with additional parameters", {
set.seed(123)
sim <- test_simulate_infections(
generation_time = generation_time_opts(fix_dist(example_generation_time)),
delays = delay_opts(fix_dist(example_reporting_delay)),
obs = obs_opts(family = "negbin", phi = list(mean = 0.5, sd = 0))
)
expect_equal(nrow(sim), 2 * nrow(R))
expect_snapshot_output(sim)
set.seed(Sys.time())
})

test_that("simulate_infections fails with uncertain parameters", {
Expand Down