@@ -27,7 +27,7 @@ update_routing_prob <- function(param, routing_name, updates) {
2727
2828 params_list <- param $ dist_config [[routing_name ]]$ params
2929
30- if (is.null(names(updates )) || any( names(updates ) == " " )) {
30+ if (is.null(names(updates )) || ! all(nzchar( names(updates )) )) {
3131 stop(" 'updates' must be a named vector or list" , call. = FALSE )
3232 }
3333
@@ -94,15 +94,15 @@ test_that("model errors for invalid asu_los values", {
9494test_that(" model errors for invalid asu_routing probabilities" , {
9595 param <- parameters()
9696 # Non-numeric value
97- param <- update_routing_prob(param , " asu_routing_stroke" , c(" rehab" = " a" ))
97+ param <- update_routing_prob(param , " asu_routing_stroke" , c(rehab = " a" ))
9898 expect_error(
9999 model(param = param , run_number = 1L ),
100100 ' Routing vector "asu_routing_stroke$params$prob" must be numeric.' ,
101101 fixed = TRUE
102102 )
103103 # Probability out of bounds
104104 param <- parameters()
105- param <- update_routing_prob(param , " asu_routing_stroke" , c(" rehab" = - 0.1 ))
105+ param <- update_routing_prob(param , " asu_routing_stroke" , c(rehab = - 0.1 ))
106106 expect_error(
107107 model(param = param , run_number = 1L ),
108108 ' All values in routing vector "asu_routing_stroke$params$prob" must be between 0 and 1.' , # nolint: line_length_linter
@@ -111,7 +111,7 @@ test_that("model errors for invalid asu_routing probabilities", {
111111 # Probabilities do not sum to 1
112112 param <- parameters()
113113 param <- update_routing_prob(param , " asu_routing_stroke" ,
114- c(" rehab" = 0.5 , " esd" = 0.5 , " other" = 0.5 ))
114+ c(rehab = 0.5 , esd = 0.5 , other = 0.5 ))
115115 expect_error(
116116 model(param = param , run_number = 1L ),
117117 ' Values in routing vector "asu_routing_stroke$params$prob" must sum to 1 (+-0.01).' , # nolint: line_length_linter
@@ -123,7 +123,7 @@ test_that("model errors for invalid asu_routing probabilities", {
123123test_that(" model errors for invalid rehab_routing probabilities" , {
124124 # Probabilities should be within 0 and 1
125125 param <- parameters()
126- param <- update_routing_prob(param , " rehab_routing_other" , c(" esd" = 1.5 ))
126+ param <- update_routing_prob(param , " rehab_routing_other" , c(esd = 1.5 ))
127127 expect_error(
128128 model(param = param , run_number = 1L ),
129129 ' All values in routing vector "rehab_routing_other$params$prob" must be between 0 and 1.' , # nolint: line_length_linter
@@ -133,7 +133,7 @@ test_that("model errors for invalid rehab_routing probabilities", {
133133 # Probabilities should sum to 1
134134 param <- parameters()
135135 param <- update_routing_prob(param , " rehab_routing_stroke" ,
136- c(" esd" = 0.8 , " other" = 0.3 ))
136+ c(esd = 0.8 , other = 0.3 ))
137137 expect_error(
138138 model(param = param , run_number = 1L ),
139139 ' Values in routing vector "rehab_routing_stroke$params$prob" must sum to 1 (+-0.01)' , # nolint: line_length_linter
@@ -143,40 +143,58 @@ test_that("model errors for invalid rehab_routing probabilities", {
143143
144144
145145patrick :: with_parameters_test_that(
146- " model errors for invalid/ missing/ extra keys in parameters" ,
146+ " model errors for invalid, missing, and extra keys in parameters" ,
147147 {
148148 param <- parameters()
149149 param <- mod(param )
150150 expect_error(model(run_number = 0L , param = param ), msg , fixed = TRUE )
151151 },
152152 patrick :: cases(
153153 missing_number_of_runs = list (
154- mod = function (p ) { p $ number_of_runs <- NULL ; p },
154+ mod = function (p ) {
155+ p $ number_of_runs <- NULL
156+ p
157+ },
155158 msg = " Problem in param. Missing: number_of_runs. Extra: ."
156159 ),
157160 # Missing key in param$dist_config
158161 missing_rehab_arrival_neuro = list (
159- mod = function (p ) { p $ dist_config $ rehab_arrival_neuro <- NULL ; p },
162+ mod = function (p ) {
163+ p $ dist_config $ rehab_arrival_neuro <- NULL
164+ p
165+ },
160166 msg = " Problem in param$dist_config. Missing: rehab_arrival_neuro. Extra: ." # nolint: line_length_linter
161167 ),
162168 # Missing specific dist_config key
163169 missing_rehab_los_tia = list (
164- mod = function (p ) { p $ dist_config $ rehab_los_tia $ params <- NULL ; p },
170+ mod = function (p ) {
171+ p $ dist_config $ rehab_los_tia $ params <- NULL
172+ p
173+ },
165174 msg = " Missing required parameter(s) in param$dist_configrehab_los_tia: params. Allowed: class_name, params" # nolint: line_length_linter
166175 ),
167176 # Extra key in top-level param
168177 extra_top_level = list (
169- mod = function (p ) { p $ extra_key <- 5L ; p },
178+ mod = function (p ) {
179+ p $ extra_key <- 5L
180+ p
181+ },
170182 msg = " Problem in param. Missing: . Extra: extra_key."
171183 ),
172184 # Extra key in param$dist_config
173185 extra_in_dist_config = list (
174- mod = function (p ) { p $ dist_config $ extra_key <- 5L ; p },
186+ mod = function (p ) {
187+ p $ dist_config $ extra_key <- 5L
188+ p
189+ },
175190 msg = " Problem in param$dist_config. Missing: . Extra: extra_key."
176191 ),
177192 # Extra key in nested dist_config entry
178193 extra_in_asu_arrival_stroke = list (
179- mod = function (p ) { p $ dist_config $ asu_arrival_stroke $ extra_key <- 5L ; p },
194+ mod = function (p ) {
195+ p $ dist_config $ asu_arrival_stroke $ extra_key <- 5L
196+ p
197+ },
180198 msg = " Unrecognised parameter(s) in param$dist_configasu_arrival_stroke: extra_key. Allowed: class_name, params" # nolint: line_length_linter
181199 )
182200 )
0 commit comments