Skip to content

Commit be5c4ed

Browse files
committed
test(functional): add some tests for missing values + impact of adjusting parameters
1 parent 4aa68cc commit be5c4ed

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

tests/testthat/test-functionaltest.R

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,64 @@ test_that("model errors for extra keys in asu_arrivals", {
113113
"Extra keys: extra."
114114
)
115115
})
116+
117+
118+
# -----------------------------------------------------------------------------
119+
# 2. Run results
120+
# -----------------------------------------------------------------------------
121+
122+
test_that("values are non-negative and not NA", {
123+
param <- create_parameters(
124+
warm_up_period = 20L, data_collection_period = 20L,
125+
cores = 1L, number_of_runs = 1L
126+
)
127+
results <- runner(param = param)
128+
129+
# Check that at least one patient was processed
130+
expect_gt(nrow(results[["arrivals"]]), 0L)
131+
132+
# Check that length of stay is greater than 0
133+
expect_true(all(results[["arrivals"]][["start_time"]] > 0L))
134+
135+
# Check that there are no missing values
136+
expect_false(any(is.na(
137+
results[["arrivals"]][c("name", "start_time", "resource", "replication")]
138+
)))
139+
expect_false(any(is.na(results[["occupancy"]])))
140+
expect_false(any(is.na(results[["occupancy_stats"]][["asu_bed"]])))
141+
expect_false(any(is.na(results[["occupancy_stats"]][["rehab_bed"]])))
142+
})
143+
144+
145+
patrick::with_parameters_test_that(
146+
"adjusting parameters decreases arrivals",
147+
{
148+
# Set some defaults
149+
default_param <- create_parameters(
150+
warm_up_period = 100L, data_collection_period = 200L,
151+
cores = 1L, number_of_runs = 1L
152+
)
153+
154+
# Set up parameter sets
155+
init_param <- default_param
156+
adj_param <- default_param
157+
if (is.null(metric)) {
158+
init_param[[group]][[patient]] <- init_value
159+
adj_param[[group]][[patient]] <- adj_value
160+
} else {
161+
init_param[[group]][[patient]][[metric]] <- init_value
162+
adj_param[[group]][[patient]][[metric]] <- adj_value
163+
}
164+
165+
# Run model and compare number of arrivals
166+
init_arrivals <- nrow(runner(param = init_param)[["arrivals"]])
167+
adj_arrivals <- nrow(runner(param = adj_param)[["arrivals"]])
168+
expect_gt(init_arrivals, adj_arrivals)
169+
},
170+
patrick::cases(
171+
list(group = "asu_arrivals", patient = "stroke", metric = NULL,
172+
init_value = 2L, adj_value = 6L),
173+
list(group = "rehab_los", patient = "stroke_noesd", metric = "mean",
174+
init_value = 30L, adj_value = 10L)
175+
)
176+
)

0 commit comments

Comments
 (0)