Skip to content

Commit

Permalink
use snapshot tests for regression testing .sim_network_bp
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Feb 7, 2024
1 parent ca5b4fa commit daacbd7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 33 deletions.
45 changes: 45 additions & 0 deletions tests/testthat/_snaps/sim_network_bp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# .sim_network_bp works as expected

Code
.sim_network_bp(contact_distribution = contact_distribution, contact_interval = contact_interval,
prob_infect = 0.5, config = create_config())
Output
id ancestor generation infected time
1 1 NA 1 infected 0.00000000
2 2 1 2 contact 1.88240160
3 3 1 2 infected 1.80451250
4 4 3 3 infected 0.05896314
5 5 3 3 contact 1.15835525
6 6 3 3 contact 0.99001994
7 7 4 4 infected 2.14036129
8 8 7 5 contact 0.46988251
9 9 7 5 contact 0.69425308
10 10 7 5 contact 0.06819735

# .sim_network_bp works as expected with no contacts

Code
.sim_network_bp(contact_distribution = contact_distribution, contact_interval = contact_interval,
prob_infect = 0.5, config = create_config())
Output
id ancestor generation infected time
1 1 NA 1 infected 0

# .sim_network_bp works as expected with unadjusted network

Code
.sim_network_bp(contact_distribution = contact_distribution, contact_interval = contact_interval,
prob_infect = 0.5, config = create_config(network = "unadjusted"))
Output
id ancestor generation infected time
1 1 NA 1 infected 0.00000000
2 2 1 2 contact 1.88240160
3 3 1 2 infected 1.80451250
4 4 3 3 infected 0.05896314
5 5 3 3 contact 1.15835525
6 6 3 3 contact 0.99001994
7 7 4 4 infected 2.14036129
8 8 7 5 contact 0.46988251
9 9 7 5 contact 0.69425308
10 10 7 5 contact 0.06819735

54 changes: 21 additions & 33 deletions tests/testthat/test-sim_network_bp.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ suppressMessages({

test_that(".sim_network_bp works as expected", {
set.seed(1)
res <- .sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config()
)
expect_s3_class(res, class = "data.frame")
expect_identical(dim(res), c(10L, 5L))
expect_identical(
colnames(res),
c("id", "ancestor", "generation", "infected", "time")
expect_snapshot(
.sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config()
)
)
})

Expand All @@ -46,32 +42,24 @@ test_that(".sim_network_bp works as expected with no contacts", {
)
)
set.seed(1)
res <- .sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config()
)
expect_s3_class(res, class = "data.frame")
expect_identical(dim(res), c(1L, 5L))
expect_identical(
colnames(res),
c("id", "ancestor", "generation", "infected", "time")
expect_snapshot(
.sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config()
)
)
})

test_that(".sim_network_bp works as expected with unadjusted network", {
set.seed(1)
res <- .sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config(network = "unadjusted")
)
expect_s3_class(res, class = "data.frame")
expect_identical(dim(res), c(10L, 5L))
expect_identical(
colnames(res),
c("id", "ancestor", "generation", "infected", "time")
expect_snapshot(
.sim_network_bp(
contact_distribution = contact_distribution,
contact_interval = contact_interval,
prob_infect = 0.5,
config = create_config(network = "unadjusted")
)
)
})

0 comments on commit daacbd7

Please sign in to comment.