Skip to content

Commit 3df6fcd

Browse files
tests
1 parent 35bf51a commit 3df6fcd

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

R/formula_list_generators.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ handle_rate_args = function(rate, abs_rate, flow_name) {
3838
warning(
3939
"The abs_rate argument is deprecated; "
4040
, "please use 'flow_name' instead"
41+
, sprintf("\nThis warning concerns the following rate:\n%s", rate)
4142
)
4243
if (!is.null(flow_name)) {
44+
## I do not think it is possible to get here
4345
stop(
4446
"You used both the 'abs_rate' and 'flow_name' arguments. "
4547
, "Please only use 'flow_name', as 'abs_rate' is deprecated."
48+
, sprintf("\nThis error concerns the following rate:\n%s", rate)
4649
)
4750
}
4851
flow_name = abs_rate
@@ -53,6 +56,7 @@ handle_rate_args = function(rate, abs_rate, flow_name) {
5356
stop(
5457
"flow_name must be specified when rate is a one_sided formula "
5558
, "or character string."
59+
, sprintf("\nThis error concerns following rate:\n%s", rate)
5660
)
5761
}
5862
rate = two_sided(flow_name, rate)

tests/testthat/test-flow-frame.R

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
test_that("flow function arg errors and warnings are appropriate", {
2+
expect_error(
3+
mp_per_capita_flow(from = "S", to = "I", rate = "beta * I")
4+
, "flow_name must be specified when rate is a one_sided formula or character string"
5+
)
6+
expect_error(
7+
mp_inflow(to = "I", rate = "beta")
8+
, "flow_name must be specified when rate is a one_sided formula or character string"
9+
)
10+
expect_error(
11+
mp_outflow(from = "S", rate = "beta")
12+
, "flow_name must be specified when rate is a one_sided formula or character string"
13+
)
14+
expect_error(
15+
mp_per_capita_inflow(from = "N", to = "S", rate = "mu")
16+
, "flow_name must be specified when rate is a one_sided formula or character string"
17+
)
18+
expect_error(
19+
mp_per_capita_outflow(from = "S", rate = "beta")
20+
, "flow_name must be specified when rate is a one_sided formula or character string"
21+
)
22+
expect_warning(
23+
mp_per_capita_flow(from = "S", to = "I", rate = "beta * I", abs_rate = "infection")
24+
, "The abs_rate argument is deprecated; please use 'flow_name' instead"
25+
)
26+
expect_warning(
27+
mp_inflow(to = "I", rate = "beta", abs_rate = "infection")
28+
, "The abs_rate argument is deprecated; please use 'flow_name' instead"
29+
)
30+
expect_warning(
31+
mp_inflow(to = "I", rate = "beta", abs_rate = "infection")
32+
, "The abs_rate argument is deprecated; please use 'flow_name' instead"
33+
)
34+
expect_warning(
35+
mp_per_capita_inflow(from = "N", to = "S", rate = "mu", abs_rate = "birth")
36+
, "The abs_rate argument is deprecated; please use 'flow_name' instead"
37+
)
38+
expect_warning(
39+
mp_per_capita_outflow(from = "S", rate = "beta", abs_rate = "death")
40+
, "The abs_rate argument is deprecated; please use 'flow_name' instead"
41+
)
42+
})
43+
44+
test_that("empty specs give empty information", {
45+
expect_identical(nrow(mp_flow_frame(mp_tmb_model_spec())), 0L)
46+
expect_identical(mp_state_vars(mp_tmb_model_spec()), character())
47+
})
48+
49+
test_that("warnings given if formulas are between flows", {
50+
expect_warning({
51+
mp_tmb_model_spec(
52+
during = list(
53+
mp_per_capita_flow("S", "I", "beta * I / N", "infection")
54+
, N ~ S + I
55+
, mp_per_capita_flow("I", "R", "gamma", "recovery")
56+
)
57+
)
58+
}
59+
, "Raw formula-valued expressions were inserted between flow-based expressions"
60+
)
61+
})
62+
63+
test_that("find all paths works with non-dag", {
64+
shiver = test_cache_read("SPEC-shiver.rds")
65+
expect_setequal(
66+
shiver |> mp_flow_frame(loops = "^vacc") |> find_all_paths("S")
67+
, list(
68+
c("S", "E", "I", "H", "R")
69+
, c("S", "E", "I", "R")
70+
, c("S", "V", "E", "I", "H", "R")
71+
, c("S", "V", "E", "I", "R")
72+
)
73+
)
74+
})

0 commit comments

Comments
 (0)