@@ -15,7 +15,7 @@ test_that("compute_grid_info - recipe only", {
1515
1616 expect_equal(res $ .iter_preprocessor , 1 : 5 )
1717 expect_equal(res $ .msg_preprocessor , paste0(" preprocessor " , 1 : 5 , " /5" ))
18- expect_equal(res $ deg_free , grid $ deg_free )
18+ expect_equal(sort( res $ deg_free ), sort( grid $ deg_free ) )
1919 expect_equal(res $ .iter_model , rep(1 , 5 ))
2020 expect_equal(res $ .iter_config , as.list(paste0(" Preprocessor" , 1 : 5 , " _Model1" )))
2121 expect_equal(res $ .msg_model , paste0(" preprocessor " , 1 : 5 , " /5, model 1/1" ))
@@ -27,6 +27,7 @@ test_that("compute_grid_info - recipe only", {
2727 ignore.order = TRUE
2828 )
2929 expect_equal(nrow(res ), 5 )
30+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
3031})
3132
3233test_that(" compute_grid_info - model only (no submodels)" , {
@@ -57,6 +58,7 @@ test_that("compute_grid_info - model only (no submodels)", {
5758 ignore.order = TRUE
5859 )
5960 expect_equal(nrow(res ), 5 )
61+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
6062})
6163
6264test_that(" compute_grid_info - model only (with submodels)" , {
@@ -107,8 +109,8 @@ test_that("compute_grid_info - recipe and model (no submodels)", {
107109
108110 expect_equal(res $ .iter_preprocessor , 1 : 5 )
109111 expect_equal(res $ .msg_preprocessor , paste0(" preprocessor " , 1 : 5 , " /5" ))
110- expect_equal(res $ learn_rate , grid $ learn_rate )
111- expect_equal(res $ deg_free , grid $ deg_free )
112+ expect_equal(sort( res $ learn_rate ), sort( grid $ learn_rate ) )
113+ expect_equal(sort( res $ deg_free ), sort( grid $ deg_free ) )
112114 expect_equal(res $ .iter_model , rep(1 , 5 ))
113115 expect_equal(res $ .iter_config , as.list(paste0(" Preprocessor" , 1 : 5 , " _Model1" )))
114116 expect_equal(res $ .msg_model , paste0(" preprocessor " , 1 : 5 , " /5, model 1/1" ))
@@ -120,6 +122,7 @@ test_that("compute_grid_info - recipe and model (no submodels)", {
120122 ignore.order = TRUE
121123 )
122124 expect_equal(nrow(res ), 5 )
125+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
123126})
124127
125128test_that(" compute_grid_info - recipe and model (with submodels)" , {
@@ -169,6 +172,7 @@ test_that("compute_grid_info - recipe and model (with submodels)", {
169172 )
170173 expect_equal(nrow(res ), 3 )
171174})
175+
172176test_that(" compute_grid_info - recipe and model (with and without submodels)" , {
173177 library(workflows )
174178 library(parsnip )
@@ -185,25 +189,30 @@ test_that("compute_grid_info - recipe and model (with and without submodels)", {
185189 # use grid_regular to (partially) trigger submodel trick
186190 set.seed(1 )
187191 param_set <- extract_parameter_set_dials(wflow )
188- grid <- bind_rows(grid_regular(param_set ), grid_space_filling(param_set ))
192+ grid <-
193+ bind_rows(grid_regular(param_set ), grid_space_filling(param_set )) %> %
194+ arrange(deg_free , loss_reduction , trees )
189195 res <- compute_grid_info(wflow , grid )
190196
191197 expect_equal(length(unique(res $ .iter_preprocessor )), 5 )
192198 expect_equal(
193199 unique(res $ .msg_preprocessor ),
194200 paste0(" preprocessor " , 1 : 5 , " /5" )
195201 )
196- expect_equal(res $ trees , c(rep(max(grid $ trees ), 10 ), 1 ))
202+ expect_equal(sort( res $ trees ), sort( c(rep(max(grid $ trees ), 10 ), 1 ) ))
197203 expect_equal(unique(res $ .iter_model ), 1 : 3 )
198204 expect_equal(
199- res $ .iter_config [1 : 3 ],
205+ res $ .iter_config [res $ .iter_preprocessor == 1 ],
200206 list (
201- c(" Preprocessor1_Model1 " , " Preprocessor1_Model2 " , " Preprocessor1_Model3 " , " Preprocessor1_Model4 " ),
202- c(" Preprocessor2_Model1 " , " Preprocessor2_Model2 " , " Preprocessor2_Model3 " ),
203- c(" Preprocessor3_Model1 " , " Preprocessor3_Model2 " , " Preprocessor3_Model3 " )
207+ c(" Preprocessor1_Model01 " , " Preprocessor1_Model02 " , " Preprocessor1_Model03 " , " Preprocessor1_Model04 " ),
208+ c(" Preprocessor1_Model05 " , " Preprocessor1_Model06 " , " Preprocessor1_Model07 " ),
209+ c(" Preprocessor1_Model08 " , " Preprocessor1_Model09 " , " Preprocessor1_Model10 " )
204210 )
205211 )
206- expect_equal(res $ .msg_model [1 : 3 ], paste0(" preprocessor " , 1 : 3 , " /5, model 1/3" ))
212+ expect_equal(
213+ res $ .msg_model [res $ .iter_preprocessor == 1 ],
214+ paste0(" preprocessor 1/5, model " , 1 : 3 , " /3" )
215+ )
207216 expect_equal(
208217 res $ .submodels [1 : 3 ],
209218 list (
@@ -212,6 +221,12 @@ test_that("compute_grid_info - recipe and model (with and without submodels)", {
212221 list (trees = c(1L , 1000L ))
213222 )
214223 )
224+ expect_equal(
225+ res %> %
226+ mutate(num_models = purrr :: map_int(.iter_config , length )) %> %
227+ summarize(n = sum(num_models ), .by = c(deg_free )),
228+ grid %> % count(deg_free )
229+ )
215230 expect_named(
216231 res ,
217232 c(" .iter_preprocessor" , " .msg_preprocessor" , " deg_free" , " trees" ,
@@ -325,4 +340,5 @@ test_that("compute_grid_info - recipe and model (no submodels but has inner grid
325340 ignore.order = TRUE
326341 )
327342 expect_equal(nrow(res ), 9 )
343+ expect_equal(vctrs :: vec_unique_count(res $ .iter_config ), nrow(grid ))
328344})
0 commit comments