Skip to content

Commit 92a393e

Browse files
committed
add tests
1 parent e962ac8 commit 92a393e

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
test_that("primary arguments", {
3+
new_empty_quosure <- function(expr) {
4+
rlang::new_quosure(expr, env = rlang::empty_env())
5+
}
6+
7+
ph_penalty <- proportional_hazards(penalty = 0.05)
8+
expect_equal(
9+
ph_penalty$args,
10+
list(penalty = new_empty_quosure(0.05),
11+
mixture = new_empty_quosure(NULL))
12+
)
13+
14+
ph_mixture <- proportional_hazards(mixture = 0.34)
15+
expect_equal(
16+
ph_mixture$args,
17+
list(penalty = new_empty_quosure(NULL),
18+
mixture = new_empty_quosure(0.34))
19+
)
20+
21+
ph_mixture_v <- proportional_hazards(mixture = varying())
22+
expect_equal(
23+
ph_mixture_v$args,
24+
list(penalty = new_empty_quosure(NULL),
25+
mixture = new_empty_quosure(varying()))
26+
)
27+
})
28+
29+
test_that("printing", {
30+
expect_output(
31+
print(proportional_hazards()),
32+
"Proportional Hazards Model Specification \\(censored regression\\)"
33+
)
34+
})
35+
36+
test_that("updating", {
37+
new_empty_quosure <- function(expr) {
38+
rlang::new_quosure(expr, env = rlang::empty_env())
39+
}
40+
41+
basic <- proportional_hazards()
42+
43+
update_num <- update(basic, penalty = 0.05)
44+
expect_equal(
45+
update_num$args,
46+
list(penalty = new_empty_quosure(0.05),
47+
mixture = new_empty_quosure(NULL))
48+
)
49+
50+
param_tibb <- tibble::tibble(penalty = 0.05)
51+
update_tibb <- update(basic, param_tibb)
52+
expect_equal(
53+
update_tibb$args,
54+
list(penalty = 0.05,
55+
mixture = new_empty_quosure(NULL))
56+
)
57+
58+
param_list <- as.list(param_tibb)
59+
update_list <- update(basic, param_list)
60+
expect_equal(
61+
update_list$args,
62+
list(penalty = 0.05,
63+
mixture = new_empty_quosure(NULL))
64+
)
65+
})
66+
67+
68+
test_that("bad input", {
69+
expect_error(proportional_hazards(mode = ", classification"))
70+
})
71+
72+
test_that("wrong fit interface", {
73+
expect_error(
74+
proportional_hazards() %>% fit_xy(),
75+
"must use the formula interface"
76+
)
77+
})

0 commit comments

Comments
 (0)