Skip to content

Commit 7b9a8ce

Browse files
committed
add some basic unit tests for the export of estimated models
1 parent 4f727a4 commit 7b9a8ce

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tests/testthat/test-double_ml_active_bindings.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ test_that("Not setable fields", {
4040
msg = "can't set field learner"
4141
expect_error(dml_plr$learner <- "abc",
4242
regexp = msg)
43+
msg = "can't set field models"
44+
expect_error(dml_plr$models <- 5,
45+
regexp = msg)
4346
msg = "can't set field n_folds"
4447
expect_error(dml_plr$n_folds <- 5,
4548
regexp = msg)

tests/testthat/test-double_ml_plr_export_preds.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ patrick::with_parameters_test_that("Unit tests for for the export of predictions
4646
n_folds = n_folds,
4747
score = score)
4848
set.seed(3141)
49-
double_mlplr_obj$fit(store_predictions = TRUE)
49+
double_mlplr_obj$fit(store_predictions = TRUE, store_models = TRUE)
5050

51+
browser()
5152
set.seed(3141)
5253
Xnames = names(df)[names(df) %in% c("y", "d", "z") == FALSE]
5354
indx = (names(df) %in% c(Xnames, "y"))
@@ -99,14 +100,20 @@ patrick::with_parameters_test_that("Unit tests for for the export of predictions
99100
expect_equal(as.vector(double_mlplr_obj$predictions$ml_g),
100101
as.vector(preds_g$response),
101102
tolerance = 1e-8)
103+
expect_class(double_mlplr_obj$models$ml_g$d[[1]][[1]],
104+
"LearnerRegr")
102105
}
103106

104107
expect_equal(as.vector(double_mlplr_obj$predictions$ml_l),
105108
as.vector(preds_l$response),
106109
tolerance = 1e-8)
110+
expect_class(double_mlplr_obj$models$ml_l$d[[1]][[1]],
111+
"LearnerRegr")
107112

108113
expect_equal(as.vector(double_mlplr_obj$predictions$ml_m),
109114
as.vector(preds_m$response),
110115
tolerance = 1e-8)
116+
expect_class(double_mlplr_obj$models$ml_m$d[[1]][[1]],
117+
"LearnerRegr")
111118
}
112119
)

0 commit comments

Comments
 (0)