Skip to content

Commit f569b38

Browse files
committed
Add/update tests for model/data mode mismatch
1 parent ca2f22b commit f569b38

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

tests/testthat/test_boost_tree_xgboost.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ test_that('xgboost execution, regression', {
122122
),
123123
regexp = NA
124124
)
125+
126+
expect_error(
127+
res <- parsnip::fit_xy(
128+
car_basic,
129+
x = mtcars[, num_pred],
130+
y = factor(mtcars$vs),
131+
control = ctrl
132+
),
133+
regexp = "For a regression model"
134+
)
125135
})
126136

127137

tests/testthat/test_linear_reg.R

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ test_that('lm execution', {
241241
regexp = NA
242242
)
243243

244+
expect_error(
245+
res <- fit_xy(
246+
hpc_basic,
247+
x = hpc[, num_pred],
248+
y = hpc$class,
249+
control = ctrl
250+
),
251+
regexp = "For a regression model"
252+
)
253+
244254
expect_error(
245255
res <- fit(
246256
hpc_basic,
@@ -250,13 +260,15 @@ test_that('lm execution', {
250260
)
251261
)
252262

253-
lm_form_catch <- fit(
254-
hpc_basic,
255-
hpc_bad_form,
256-
data = hpc,
257-
control = caught_ctrl
263+
expect_error(
264+
lm_form_catch <- fit(
265+
hpc_basic,
266+
hpc_bad_form,
267+
data = hpc,
268+
control = caught_ctrl
269+
),
270+
regexp = "For a regression model"
258271
)
259-
expect_true(inherits(lm_form_catch$fit, "try-error"))
260272

261273
## multivariate y
262274

tests/testthat/test_mars.R

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,14 @@ test_that('mars execution', {
151151
expect_true(has_multi_predict(res))
152152
expect_equal(multi_predict_args(res), "num_terms")
153153

154-
expect_message(
155-
expect_error(
156-
res <- fit(
157-
hpc_basic,
158-
hpc_bad_form,
159-
data = hpc,
160-
control = ctrl
161-
)
154+
expect_error(
155+
res <- fit(
156+
hpc_basic,
157+
hpc_bad_form,
158+
data = hpc,
159+
control = ctrl
162160
),
163-
"Timing stopped"
161+
regexp = "For a regression model"
164162
)
165163

166164
## multivariate y
@@ -203,7 +201,7 @@ test_that('mars prediction', {
203201
input_fields =
204202
c(430.476046435458, 158.833790342308, 218.07635084308,
205203
158.833790342308, 158.833790342308)
206-
),
204+
),
207205
class = "data.frame", row.names = c(NA, -5L)
208206
)
209207

tests/testthat/test_rand_forest_ranger.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ test_that('ranger classification execution', {
3737
)
3838
expect_output(print(res), "parsnip model object")
3939

40+
expect_error(
41+
res <- fit(
42+
lc_ranger,
43+
funded_amnt ~ Class + term,
44+
data = lending_club,
45+
control = ctrl
46+
),
47+
regexp = "For a classification model"
48+
)
49+
4050
expect_error(
4151
res <- fit_xy(
4252
lc_ranger,

0 commit comments

Comments
 (0)