Skip to content

Commit 4652db8

Browse files
authored
Merge pull request #791 from tidymodels/tests-survival
Tests for survival models
2 parents de88664 + e36ab4b commit 4652db8

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/testthat/_snaps/translate.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,24 @@
15271527
min_rows(5, data, 5)
15281528
15291529

1530+
# arguments (proportional_hazards)
1531+
1532+
Code
1533+
basic %>% translate_args()
1534+
Output
1535+
list()
1536+
1537+
---
1538+
1539+
Code
1540+
basic_incomplete %>% translate_args()
1541+
Condition
1542+
Error in `.check_glmnet_penalty_fit()`:
1543+
! For the glmnet engine, `penalty` must be a single number (or a value of `tune()`).
1544+
* There are 0 values for `penalty`.
1545+
* To try multiple values for total regularization, use the tune package.
1546+
* To predict multiple penalties, use `multi_predict()`
1547+
15301548
# arguments (rand_forest)
15311549

15321550
Code
@@ -1877,6 +1895,13 @@
18771895
env: empty
18781896
18791897

1898+
# arguments (survival_reg)
1899+
1900+
Code
1901+
basic %>% translate_args()
1902+
Output
1903+
list()
1904+
18801905
# arguments (svm_linear)
18811906

18821907
Code

tests/testthat/test_translate.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ test_that("arguments (nearest_neighbor)", {
199199
expect_snapshot(translate_args(dist_power %>% set_engine("kknn")))
200200
})
201201

202+
203+
# translate.proportional_hazards ------------------------------------------
204+
test_that("arguments (proportional_hazards)", {
205+
suppressMessages({
206+
basic <- proportional_hazards(penalty = 0.1) %>% set_engine("glmnet")
207+
basic_incomplete <- proportional_hazards() %>% set_engine("glmnet")
208+
})
209+
210+
# this is empty because the engines are not defined in parsnip
211+
expect_snapshot(basic %>% translate_args())
212+
# but we can check for the error if there is no penalty for glmnet
213+
expect_snapshot(error = TRUE,
214+
basic_incomplete %>% translate_args()
215+
)
216+
})
217+
202218
# translate.rand_forest --------------------------------------------------------
203219
test_that("arguments (rand_forest)", {
204220
basic <- rand_forest(mode = "regression")
@@ -237,6 +253,17 @@ test_that("arguments (surv_reg)", {
237253
expect_snapshot(translate_args(dist_v %>% set_engine("flexsurv")))
238254
})
239255

256+
# translate.survival_reg -----------------------------------------------------------
257+
test_that("arguments (survival_reg)", {
258+
suppressMessages({
259+
basic <- survival_reg()
260+
})
261+
262+
# this is empty because the engines are not defined in parsnip
263+
expect_snapshot(basic %>% translate_args())
264+
265+
})
266+
240267
# translate.svm_linear ---------------------------------------------------------
241268
test_that("arguments (svm_linear)", {
242269
basic <- svm_linear(mode = "regression")

0 commit comments

Comments
 (0)