Skip to content

Commit 99c6826

Browse files
committed
additional unit tests for tidymodels/parsnip#893
1 parent 03c1e3f commit 99c6826

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# survival helpers
2+
3+
The object does not have class `Surv`.
4+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
test_that('survival helpers', {
2+
skip_if_not_installed("parsnip", minimum_version = "1.0.4.9001")
3+
library(survival)
4+
library(parsnip)
5+
6+
times <- seq(1, 100, length.out = 5)
7+
times2 <- seq(100, 200, length.out = 5)
8+
events <- c(1, 0, 1, 0, 1)
9+
10+
right_c <- Surv(times, events)
11+
left_c <- Surv(times, events, type = "left")
12+
intv_c <- Surv(times, times2, events, type = "interval")
13+
count_c <- Surv(times, times2, events)
14+
15+
expect_true(parsnip:::.is_surv(right_c))
16+
expect_false(parsnip:::.is_surv(1, fail = FALSE))
17+
expect_snapshot_error(parsnip:::.is_surv(1))
18+
19+
expect_true(.is_censored_right(right_c))
20+
expect_false(.is_censored_right(left_c))
21+
22+
expect_equal(
23+
.extract_surv_time(right_c),
24+
times
25+
)
26+
expect_equal(
27+
.extract_surv_time(left_c),
28+
times
29+
)
30+
expect_equal(
31+
.extract_surv_time(intv_c),
32+
tibble::tibble(time1 = times, time2 = rep(1.0, 5))
33+
)
34+
expect_equal(
35+
.extract_surv_time(count_c),
36+
tibble::tibble(start = times, stop = times2)
37+
)
38+
39+
expect_equal(
40+
.extract_surv_status(right_c),
41+
events
42+
)
43+
expect_equal(
44+
.extract_surv_status(left_c),
45+
events
46+
)
47+
expect_equal(
48+
.extract_surv_status(intv_c),
49+
events
50+
)
51+
expect_equal(
52+
.extract_surv_status(count_c),
53+
events
54+
)
55+
56+
})

0 commit comments

Comments
 (0)