@@ -6,7 +6,7 @@ expect_stdout(print(trans_models_empty), "Transition Models Table")
66expect_equal(nrow(trans_models_empty ), 0L )
77expect_true(inherits(trans_models_empty , " trans_models_t" ))
88
9- # Test creation with data (updated structure with sampled_coords and fit_call)
9+ # Test creation with data
1010trans_models_t <- as_trans_models_t(data.table :: data.table(
1111 id_trans = 1L ,
1212 model_family = " rf" ,
@@ -16,9 +16,6 @@ trans_models_t <- as_trans_models_t(data.table::data.table(
1616 goodness_of_fit = list (
1717 list (auc = 0.8 , rmse = 0.15 )
1818 ),
19- sampled_coords = list (
20- data.table :: data.table(id_coord = 1 : 10 , id_period = rep(1L , 10 ))
21- ),
2219 fit_call = " fit_fun(data = data, result_col = \" result\" )" ,
2320 model_obj_part = list (
2421 charToRaw(" partial model data" )
@@ -195,52 +192,35 @@ expect_message(
195192 gof_fun = gof_mock ,
196193 sample_pct = 70 ,
197194 seed = 123 ,
198- na_value = 0
195+ na_value = 0 ,
196+ other_param = " nonce"
199197 ),
200198 " Fitting partial model"
201199)
202-
203- # test DB round trip
204- expect_silent(db_tm $ trans_models_t <- partial_models )
205- expect_equivalent(db_tm $ trans_models_t , partial_models )
206-
207- expect_true(inherits(partial_models , " trans_models_t" ))
208- expect_true(nrow(partial_models ) > 0L )
209- expect_true(all(partial_models $ id_trans > 0 ))
210-
211- # Check that partial models are present
212- expect_true(all(! vapply(partial_models $ model_obj_part , is.null , logical (1 ))))
213-
214- # Check that full models are NULL
215- expect_true(all(vapply(partial_models $ model_obj_full , is.null , logical (1 ))))
216-
217- # Check that sampled_coords is present
218- expect_true(all(! vapply(partial_models $ sampled_coords , is.null , logical (1 ))))
219- first_sampled <- partial_models $ sampled_coords [[1 ]]
220- expect_true(inherits(first_sampled , " data.table" ))
221- expect_true(" id_coord" %in% names(first_sampled ))
222- expect_true(" id_period" %in% names(first_sampled ))
223-
224- # Check that fit_call is present and is character string
225- expect_true(all(nchar(partial_models $ fit_call ) > 0 ))
226- expect_true(is.character(partial_models $ fit_call ))
227-
228- # Check that fit_call contains the function name
229- first_call <- partial_models $ fit_call [1 ]
230- expect_true(grepl(" fit_mock_glm" , first_call ))
231- expect_true(grepl(" data.*result_col" , first_call ))
232-
233- # Check that goodness_of_fit is populated
234- first_gof <- partial_models $ goodness_of_fit [[1 ]]
235- expect_true(length(first_gof ) > 0 )
236- expect_true(" cor" %in% names(first_gof ) || " mse" %in% names(first_gof ))
200+ expect_equal(
201+ partial_models $ fit_call [1 ],
202+ r " {fit_mock_glm(data = data, result_col = " result " , other_param = " nonce " )}"
203+ )
204+ expect_equal(
205+ partial_models $ model_params [[1 ]],
206+ list (n_predictors = 3 , n_train = 17 , sample_pct = 70 , other_param = " nonce" )
207+ )
208+ expect_true(all(
209+ ! vapply(partial_models $ model_obj_part , is.null , logical (1 ))
210+ ))
211+ expect_equal(
212+ partial_models $ goodness_of_fit [[1 ]],
213+ list (cor = 0.6917245 , mse = 0.1610296 , n_test = 5 ),
214+ tolerance = 1e07
215+ )
237216
238217# Test that model deserialization works
239218first_model_part <- qs2 :: qs_deserialize(partial_models $ model_obj_part [[1 ]])
240219expect_true(inherits(first_model_part , " glm" ))
241220
242- # Note: Reproducibility with seed can be affected by RNG state from previous operations
243- # Skipping reproducibility test for now
221+ # test DB round trip
222+ expect_silent(db_tm $ trans_models_t <- partial_models )
223+ expect_equivalent(db_tm $ trans_models_t , partial_models )
244224
245225# Test fit_full_models
246226expect_message(
@@ -257,7 +237,6 @@ expect_message(
257237expect_silent(db_tm $ trans_models_t <- full_models )
258238expect_identical(db_tm $ trans_models_t , full_models )
259239
260-
261240expect_true(inherits(full_models , " trans_models_t" ))
262241expect_true(nrow(full_models ) > 0L )
263242
@@ -430,7 +409,6 @@ expect_equal(
430409 " model_family" ,
431410 " model_params" ,
432411 " goodness_of_fit" ,
433- " sampled_coords" ,
434412 " fit_call" ,
435413 " model_obj_part" ,
436414 " model_obj_full"
0 commit comments