Skip to content

Commit 2ff48f0

Browse files
committed
tests: add snapshots
1 parent de586be commit 2ff48f0

28 files changed

+984
-16
lines changed

NAMESPACE

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,15 @@ import(distributional)
214214
import(epiprocess)
215215
import(parsnip)
216216
import(recipes)
217-
importFrom(checkmate,assert)
218-
importFrom(checkmate,assert_character)
219217
importFrom(checkmate,assert_class)
220-
importFrom(checkmate,assert_date)
221-
importFrom(checkmate,assert_function)
222-
importFrom(checkmate,assert_int)
223-
importFrom(checkmate,assert_integer)
224-
importFrom(checkmate,assert_integerish)
225-
importFrom(checkmate,assert_logical)
226-
importFrom(checkmate,assert_number)
227218
importFrom(checkmate,assert_numeric)
228-
importFrom(checkmate,assert_scalar)
219+
importFrom(checkmate,test_character)
220+
importFrom(checkmate,test_date)
221+
importFrom(checkmate,test_function)
222+
importFrom(checkmate,test_integerish)
223+
importFrom(checkmate,test_logical)
224+
importFrom(checkmate,test_numeric)
225+
importFrom(checkmate,test_scalar)
229226
importFrom(cli,cli_abort)
230227
importFrom(cli,cli_warn)
231228
importFrom(dplyr,across)

R/epipredict-package.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## usethis namespace: start
22
#' @import epiprocess parsnip
3-
#' @importFrom checkmate assert assert_character assert_int assert_scalar
4-
#' @importFrom checkmate assert_logical assert_numeric assert_number
5-
#' @importFrom checkmate assert_integer assert_integerish
6-
#' @importFrom checkmate assert_date assert_function assert_class
3+
#' @importFrom checkmate assert_class assert_numeric test_character test_date
4+
#' @importFrom checkmate test_function test_integerish test_logical test_numeric
5+
#' @importFrom checkmate test_scalar
76
#' @importFrom cli cli_abort cli_warn
87
#' @importFrom dplyr arrange across all_of any_of bind_cols bind_rows group_by
98
#' @importFrom dplyr summarize filter mutate select left_join rename ungroup
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# arx_args checks inputs
2+
3+
Code
4+
arx_args_list(ahead = c(0, 4))
5+
Condition
6+
Error in `arx_args_list()`:
7+
! `ahead` must be a scalar.
8+
9+
---
10+
11+
Code
12+
arx_args_list(n_training = c(28, 65))
13+
Condition
14+
Error in `arx_args_list()`:
15+
! `n_training` must be a scalar.
16+
17+
---
18+
19+
Code
20+
arx_args_list(ahead = -1)
21+
Condition
22+
Error in `arx_args_list()`:
23+
! `ahead` must be a non-negative integer.
24+
25+
---
26+
27+
Code
28+
arx_args_list(ahead = 1.5)
29+
Condition
30+
Error in `arx_args_list()`:
31+
! `ahead` must be a non-negative integer.
32+
33+
---
34+
35+
Code
36+
arx_args_list(n_training = -1)
37+
Condition
38+
Error in `arx_args_list()`:
39+
! `n_training` must be a strictly positive number.
40+
41+
---
42+
43+
Code
44+
arx_args_list(n_training = 1.5)
45+
Condition
46+
Error in `arx_args_list()`:
47+
! `n_training` must be a positive integer.
48+
49+
---
50+
51+
Code
52+
arx_args_list(lags = c(-1, 0))
53+
Condition
54+
Error in `arx_args_list()`:
55+
! `lags` must be non-negative integers.
56+
57+
---
58+
59+
Code
60+
arx_args_list(lags = list(c(1:5, 6.5), 2:8))
61+
Condition
62+
Error in `arx_args_list()`:
63+
! `lags` must be non-negative integers.
64+
65+
---
66+
67+
Code
68+
arx_args_list(symmetrize = 4)
69+
Condition
70+
Error in `arx_args_list()`:
71+
! `symmetrize` must be of type <logical>.
72+
73+
---
74+
75+
Code
76+
arx_args_list(nonneg = 4)
77+
Condition
78+
Error in `arx_args_list()`:
79+
! `nonneg` must be of type <logical>.
80+
81+
---
82+
83+
Code
84+
arx_args_list(quantile_levels = -0.1)
85+
Condition
86+
Error in `arx_args_list()`:
87+
! `quantile_levels` must lie in [0, 1].
88+
89+
---
90+
91+
Code
92+
arx_args_list(quantile_levels = 1.1)
93+
Condition
94+
Error in `arx_args_list()`:
95+
! `quantile_levels` must lie in [0, 1].
96+
97+
---
98+
99+
Code
100+
arx_args_list(target_date = "2022-01-01")
101+
Condition
102+
Error in `arx_args_list()`:
103+
! `target_date` must be a date.
104+
105+
---
106+
107+
Code
108+
arx_args_list(n_training_min = "de")
109+
Condition
110+
Error in `arx_args_list()`:
111+
! `...` must be empty.
112+
x Problematic argument:
113+
* n_training_min = "de"
114+
115+
---
116+
117+
Code
118+
arx_args_list(epi_keys = 1)
119+
Condition
120+
Error in `arx_args_list()`:
121+
! `...` must be empty.
122+
x Problematic argument:
123+
* epi_keys = 1
124+
125+
# arx forecaster disambiguates quantiles
126+
127+
Code
128+
compare_quantile_args(alist, tlist)
129+
Condition
130+
Error in `compare_quantile_args()`:
131+
! You have specified different, non-default, quantiles in the trainier and `arx_args` options.
132+
i Please only specify quantiles in one location.
133+
134+
# arx_lags_validator handles named & unnamed lists as expected
135+
136+
Code
137+
arx_lags_validator(pred_vec, lags_finit_fn_switch2)
138+
Condition
139+
Error in `arx_lags_validator()`:
140+
! You have requested 2 predictor(s) but 3 different lags.
141+
i Lags must be a vector or a list with length == number of predictors.
142+
143+
---
144+
145+
Code
146+
arx_lags_validator(pred_vec, lags_init_other_name)
147+
Condition
148+
Error in `arx_lags_validator()`:
149+
! If lags is a named list, then all predictors must be present.
150+
i The predictors are `death_rate` and `case_rate`.
151+
i So lags is missing `case_rate`'.
152+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# arx_class_args checks inputs
2+
3+
Code
4+
arx_class_args_list(ahead = c(0, 4))
5+
Condition
6+
Error in `arx_class_args_list()`:
7+
! `ahead` must be a scalar.
8+
9+
---
10+
11+
Code
12+
arx_class_args_list(n_training = c(28, 65))
13+
Condition
14+
Error in `arx_class_args_list()`:
15+
! `n_training` must be a scalar.
16+
17+
---
18+
19+
Code
20+
arx_class_args_list(ahead = -1)
21+
Condition
22+
Error in `arx_class_args_list()`:
23+
! `ahead` must be a non-negative integer.
24+
25+
---
26+
27+
Code
28+
arx_class_args_list(ahead = 1.5)
29+
Condition
30+
Error in `arx_class_args_list()`:
31+
! `ahead` must be a non-negative integer.
32+
33+
---
34+
35+
Code
36+
arx_class_args_list(n_training = -1)
37+
Condition
38+
Error in `arx_class_args_list()`:
39+
! `n_training` must be a strictly positive number.
40+
41+
---
42+
43+
Code
44+
arx_class_args_list(n_training = 1.5)
45+
Condition
46+
Error in `arx_class_args_list()`:
47+
! `n_training` must be a positive integer.
48+
49+
---
50+
51+
Code
52+
arx_class_args_list(lags = c(-1, 0))
53+
Condition
54+
Error in `arx_class_args_list()`:
55+
! `lags` must be non-negative integers.
56+
57+
---
58+
59+
Code
60+
arx_class_args_list(lags = list(c(1:5, 6.5), 2:8))
61+
Condition
62+
Error in `arx_class_args_list()`:
63+
! `lags` must be non-negative integers.
64+
65+
---
66+
67+
Code
68+
arx_class_args_list(target_date = "2022-01-01")
69+
Condition
70+
Error in `arx_class_args_list()`:
71+
! `target_date` must be a date.
72+
73+
---
74+
75+
Code
76+
arx_class_args_list(n_training_min = "de")
77+
Condition
78+
Error in `arx_class_args_list()`:
79+
! `...` must be empty.
80+
x Problematic argument:
81+
* n_training_min = "de"
82+
83+
---
84+
85+
Code
86+
arx_class_args_list(epi_keys = 1)
87+
Condition
88+
Error in `arx_class_args_list()`:
89+
! `...` must be empty.
90+
x Problematic argument:
91+
* epi_keys = 1
92+

tests/testthat/_snaps/bake-method.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# bake method works in all cases
2+
3+
Code
4+
bake(prep(r, edf), NULL, composition = "matrix")
5+
Condition
6+
Error in `hardhat::recompose()`:
7+
! `data` must only contain numeric columns.
8+
i These columns aren't numeric: "geo_value" and "time_value".
9+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# training set validation works
2+
3+
Code
4+
validate_meta_match(t1, template, "geo_type", "abort")
5+
Condition
6+
Error in `validate_meta_match()`:
7+
! The `geo_type` of the training data appears to be different from that
8+
used to construct the recipe. This may result in unexpected consequences.
9+
i Training `geo_type` is 'county'.
10+
i Originally, it was 'state'.
11+
12+
---
13+
14+
Code
15+
epi_check_training_set(t4, rec)
16+
Condition
17+
Error in `epi_check_training_set()`:
18+
! The recipe specifies keys which are not in the training data.
19+
i The training set is missing columns for missing_col.
20+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# check_enough_train_data works on pooled data
2+
3+
Code
4+
epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n + 1,
5+
drop_na = FALSE) %>% prep(toy_epi_df) %>% bake(new_data = NULL)
6+
Condition
7+
Error in `prep()`:
8+
! The following columns don't have enough data to predict: x and y.
9+
10+
---
11+
12+
Code
13+
epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n - 1,
14+
drop_na = TRUE) %>% prep(toy_epi_df) %>% bake(new_data = NULL)
15+
Condition
16+
Error in `prep()`:
17+
! The following columns don't have enough data to predict: x and y.
18+
19+
# check_enough_train_data works on unpooled data
20+
21+
Code
22+
epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = n + 1, epi_keys = "geo_value",
23+
drop_na = FALSE) %>% prep(toy_epi_df) %>% bake(new_data = NULL)
24+
Condition
25+
Error in `prep()`:
26+
! The following columns don't have enough data to predict: x and y.
27+
28+
---
29+
30+
Code
31+
epi_recipe(toy_epi_df) %>% check_enough_train_data(x, y, n = 2 * n - 3,
32+
epi_keys = "geo_value", drop_na = TRUE) %>% prep(toy_epi_df) %>% bake(new_data = NULL)
33+
Condition
34+
Error in `prep()`:
35+
! The following columns don't have enough data to predict: x and y.
36+
37+
# check_enough_train_data works with all_predictors() downstream of constructed terms
38+
39+
Code
40+
epi_recipe(toy_epi_df) %>% step_epi_lag(x, lag = c(1, 2)) %>%
41+
check_enough_train_data(all_predictors(), y, n = 2 * n - 5) %>% prep(
42+
toy_epi_df) %>% bake(new_data = NULL)
43+
Condition
44+
Error in `prep()`:
45+
! The following columns don't have enough data to predict: lag_1_x, lag_2_x, and y.
46+

0 commit comments

Comments
 (0)