Skip to content

Commit 11e071b

Browse files
committed
tests(functional): add tests that adjusting parameters alters wait time, utilisation and arrivals as expected
1 parent 0cd9403 commit 11e071b

File tree

1 file changed

+86
-17
lines changed

1 file changed

+86
-17
lines changed

tests/testthat/test-functionaltest.R

Lines changed: 86 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# These verify that the system or components perform their intended
44
# functionality.
55

6+
67
test_that("values are non-negative", {
78
# Run model with standard parameters
89
raw_results <- model(run_number = 0L, param = parameters())
@@ -19,6 +20,7 @@ test_that("values are non-negative", {
1920
expect_gt(results[["utilisation_nurse"]], 0L)
2021
})
2122

23+
2224
test_that("under high demand, utilisation is valid and last patient is unseen",
2325
{
2426
# Run model with high number of arrivals and only one nurse
@@ -45,6 +47,90 @@ test_that("under high demand, utilisation is valid and last patient is unseen",
4547
}
4648
)
4749

50+
51+
test_that("runner outputs a named list with length 2 and correct names", {
52+
# Simple run of the model
53+
param <- parameters(
54+
data_collection_period = 50L, number_of_runs = 1L, cores = 1L
55+
)
56+
result <- runner(param)
57+
58+
# Check the structure
59+
expect_type(result, "list")
60+
expect_length(result, 2L)
61+
expect_named(result, c("arrivals", "resources"))
62+
63+
# Check that arrivals and resources are dataframes
64+
expect_s3_class(result[["arrivals"]], "data.frame")
65+
expect_s3_class(result[["resources"]], "data.frame")
66+
})
67+
68+
69+
patrick::with_parameters_test_that(
70+
"adjusting parameters decreases the wait time and utilisation",
71+
{
72+
# Set some defaults which will ensure sufficient arrivals/capacity to see
73+
# variation in wait time and utilisation
74+
default_param <- parameters(number_of_nurses = 4L,
75+
patient_inter = 3L,
76+
mean_n_consult_time = 15L,
77+
data_collection_period = 200L,
78+
number_of_runs = 1L)
79+
80+
# Run model with initial value
81+
init_param <- default_param
82+
init_param[[param_name]] <- init_value
83+
init_result <- get_run_results(runner(init_param))
84+
85+
# Run model with adjusted value
86+
adj_param <- default_param
87+
adj_param[[param_name]] <- adj_value
88+
adj_result <- get_run_results(runner(adj_param))
89+
90+
# Check that waiting times in the adjusted model are lower
91+
expect_lt(adj_result[["mean_waiting_time_nurse"]],
92+
init_result[["mean_waiting_time_nurse"]])
93+
94+
# Check that utilisation in the adjusted model is lower
95+
expect_lt(adj_result[["utilisation_nurse"]],
96+
init_result[["utilisation_nurse"]])
97+
},
98+
patrick::cases(
99+
list(param_name = "number_of_nurses", init_value = 3L, adj_value = 9L),
100+
list(param_name = "patient_inter", init_value = 2L, adj_value = 15L),
101+
list(param_name = "mean_n_consult_time", init_value = 30L, adj_value = 3L)
102+
)
103+
)
104+
105+
106+
patrick::with_parameters_test_that(
107+
"adjusting parameters reduces the number of arrivals",
108+
{
109+
# Set some default parameters
110+
default_param <- parameters(data_collection_period = 200L,
111+
number_of_runs = 1L)
112+
113+
# Run model with initial value
114+
init_param <- default_param
115+
init_param[[param_name]] <- init_value
116+
init_result <- get_run_results(model(run_number = 1L, init_param))
117+
118+
# Run model with adjusted value
119+
adj_param <- default_param
120+
adj_param[[param_name]] <- adj_value
121+
adj_result <- get_run_results(model(run_number = 1L, adj_param))
122+
123+
# Check that arrivals in the adjusted model are lower
124+
expect_lt(adj_result[["arrivals"]], init_result[["arrivals"]])
125+
},
126+
patrick::cases(
127+
list(param_name = "patient_inter", init_value = 2L, adj_value = 15L),
128+
list(param_name = "data_collection_period", init_value = 2000L,
129+
adj_value = 500L)
130+
)
131+
)
132+
133+
48134
test_that("the same seed returns the same result", {
49135
# Run model twice using same run number (which will set the seed)
50136
raw1 <- model(run_number = 0L, param = parameters())
@@ -63,20 +149,3 @@ test_that("the same seed returns the same result", {
63149
raw2 <- runner(param = parameters())
64150
expect_identical(get_run_results(raw1), get_run_results(raw2))
65151
})
66-
67-
test_that("runner outputs a named list with length 2 and correct names", {
68-
# Simple run of the model
69-
param <- parameters(
70-
data_collection_period = 50L, number_of_runs = 1L, cores = 1L
71-
)
72-
result <- runner(param)
73-
74-
# Check the structure
75-
expect_type(result, "list")
76-
expect_length(result, 2L)
77-
expect_named(result, c("arrivals", "resources"))
78-
79-
# Check that arrivals and resources are dataframes
80-
expect_s3_class(result[["arrivals"]], "data.frame")
81-
expect_s3_class(result[["resources"]], "data.frame")
82-
})

0 commit comments

Comments
 (0)