Skip to content

Commit bdf12e1

Browse files
authored
Merge pull request #538 from tidymodels/use-snapshot-tests
Use snapshot tests
2 parents 77fc1fe + 23200c5 commit bdf12e1

34 files changed

+1305
-203
lines changed

tests/testthat/_snaps/boot.md

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414

1515
# bad args
1616

17+
Code
18+
bootstraps(warpbreaks, strata = warpbreaks$tension)
19+
Condition
20+
Error in `bootstraps()`:
21+
! Can't select columns that don't exist.
22+
x Columns `L`, `L`, `L`, `L`, `L`, etc. don't exist.
23+
24+
---
25+
26+
Code
27+
bootstraps(warpbreaks, strata = c("tension", "wool"))
28+
Condition
29+
Error in `strata_check()`:
30+
! `strata` should be a single name or character value.
31+
32+
---
33+
1734
Code
1835
group_bootstraps(warpbreaks, tension)
1936
Condition

tests/testthat/_snaps/bootci.md

+191
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,194 @@
2828
Error in `bca_calc()`:
2929
! All statistics have missing values.
3030

31+
# Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method
32+
33+
Code
34+
int_pctl(bt_small, stats)
35+
Condition
36+
Warning:
37+
Recommend at least 1000 non-missing bootstrap resamples for term `mean`.
38+
Output
39+
# A tibble: 1 x 6
40+
term .lower .estimate .upper .alpha .method
41+
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
42+
1 mean 9.97 10.0 10.1 0.05 percentile
43+
44+
---
45+
46+
Code
47+
int_t(bt_small, stats)
48+
Condition
49+
Warning:
50+
Recommend at least 500 non-missing bootstrap resamples for term `mean`.
51+
Output
52+
# A tibble: 1 x 6
53+
term .lower .estimate .upper .alpha .method
54+
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
55+
1 mean 9.96 10.0 10.1 0.05 student-t
56+
57+
---
58+
59+
Code
60+
int_bca(bt_small, stats, .fn = get_stats)
61+
Condition
62+
Warning:
63+
Recommend at least 1000 non-missing bootstrap resamples for term `mean`.
64+
Output
65+
# A tibble: 1 x 6
66+
term .lower .estimate .upper .alpha .method
67+
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
68+
1 mean 9.96 10.0 10.1 0.05 BCa
69+
70+
# bad input
71+
72+
Code
73+
int_pctl(bt_small, id)
74+
Condition
75+
Error in `check_tidy()`:
76+
! {.arg statistics} should select a list column of tidy results.
77+
78+
---
79+
80+
Code
81+
int_pctl(bt_small, junk)
82+
Condition
83+
Error in `check_tidy()`:
84+
! {.arg statistics} should select a list column of tidy results.
85+
86+
---
87+
88+
Code
89+
int_pctl(bt_small, stats, alpha = c(0.05, 0.2))
90+
Condition
91+
Error in `int_pctl()`:
92+
! `alpha` must be a single numeric value.
93+
94+
---
95+
96+
Code
97+
int_t(bt_small, stats, alpha = "potato")
98+
Condition
99+
Error in `int_t()`:
100+
! `alpha` must be a single numeric value.
101+
102+
---
103+
104+
Code
105+
int_bca(bt_small, stats, alpha = 1:2, .fn = get_stats)
106+
Condition
107+
Error in `int_bca()`:
108+
! `alpha` must be a single numeric value.
109+
110+
---
111+
112+
Code
113+
int_pctl(vfold_cv(mtcars))
114+
Condition
115+
Error in `UseMethod()`:
116+
! no applicable method for 'int_pctl' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"
117+
118+
---
119+
120+
Code
121+
int_t(vfold_cv(mtcars))
122+
Condition
123+
Error in `UseMethod()`:
124+
! no applicable method for 'int_t' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"
125+
126+
---
127+
128+
Code
129+
int_bca(vfold_cv(mtcars))
130+
Condition
131+
Error in `UseMethod()`:
132+
! no applicable method for 'int_bca' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"
133+
134+
---
135+
136+
Code
137+
int_t(bad_bt_norm, stats)
138+
Condition
139+
Error in `check_tidy_names()`:
140+
! `statistics` should select a single column for the standard error.
141+
142+
---
143+
144+
Code
145+
int_bca(bt_norm, stats, .fn = no_dots)
146+
Condition
147+
Error in `has_dots()`:
148+
! `.fn` must have an argument `...`.
149+
150+
---
151+
152+
Code
153+
int_pctl(as.data.frame(bt_norm), stats)
154+
Condition
155+
Error in `UseMethod()`:
156+
! no applicable method for 'int_pctl' applied to an object of class "data.frame"
157+
158+
---
159+
160+
Code
161+
int_t(as.data.frame(bt_norm), stats)
162+
Condition
163+
Error in `UseMethod()`:
164+
! no applicable method for 'int_t' applied to an object of class "data.frame"
165+
166+
---
167+
168+
Code
169+
int_bca(as.data.frame(bt_norm), stats, .fn = get_stats)
170+
Condition
171+
Error in `UseMethod()`:
172+
! no applicable method for 'int_bca' applied to an object of class "data.frame"
173+
174+
---
175+
176+
Code
177+
int_t(bt_norm %>% dplyr::filter(id != "Apparent"), stats)
178+
Condition
179+
Error in `UseMethod()`:
180+
! no applicable method for 'int_t' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
181+
182+
---
183+
184+
Code
185+
int_bca(bt_norm %>% dplyr::filter(id != "Apparent"), stats, .fn = get_stats)
186+
Condition
187+
Error in `UseMethod()`:
188+
! no applicable method for 'int_bca' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
189+
190+
---
191+
192+
Code
193+
int_pctl(badder_bt_norm, bad_term)
194+
Condition
195+
Error in `check_tidy_names()`:
196+
! The tibble in `statistics` should have columns for 'estimate' and 'term'.
197+
198+
---
199+
200+
Code
201+
int_t(badder_bt_norm, bad_err)
202+
Condition
203+
Error in `check_tidy_names()`:
204+
! `statistics` should select a single column for the standard error.
205+
206+
---
207+
208+
Code
209+
int_bca(badder_bt_norm, bad_est, .fn = get_stats)
210+
Condition
211+
Error in `check_tidy_names()`:
212+
! The tibble in `statistics` should have columns for 'estimate' and 'term'.
213+
214+
---
215+
216+
Code
217+
int_pctl(badder_bt_norm, bad_num)
218+
Condition
219+
Error in `pctl_single()`:
220+
! `stats` must be a numeric vector.
221+

tests/testthat/_snaps/clustering.md

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
# bad args
22

3-
`vars` is required and must contain at least one variable in `data`.
3+
Code
4+
clustering_cv(dat1)
5+
Condition
6+
Error in `clustering_cv()`:
7+
! `vars` is required and must contain at least one variable in `data`.
48

59
---
610

7-
`v` must be a single positive integer greater than 1.
11+
Code
12+
clustering_cv(iris, Sepal.Length, v = -500)
13+
Condition
14+
Error in `clustering_cv()`:
15+
! `v` must be a single positive integer greater than 1.
816

917
---
1018

11-
The number of rows is less than `v` = 500.
19+
Code
20+
clustering_cv(iris, Sepal.Length, v = 500)
21+
Condition
22+
Error in `clustering_cv()`:
23+
! The number of rows is less than `v` = 500.
1224

1325
---
1426

15-
`cluster_function` must be one of "kmeans" or "hclust", not "not an option".
27+
Code
28+
clustering_cv(iris, Sepal.Length, cluster_function = "not an option")
29+
Condition
30+
Error in `clustering_cv()`:
31+
! `cluster_function` must be one of "kmeans" or "hclust", not "not an option".
1632

1733
---
1834

@@ -24,11 +40,19 @@
2440

2541
---
2642

27-
`repeats` must be a single positive integer.
43+
Code
44+
clustering_cv(Orange, repeats = 0)
45+
Condition
46+
Error in `clustering_cv()`:
47+
! `repeats` must be a single positive integer.
2848

2949
---
3050

31-
`repeats` must be a single positive integer.
51+
Code
52+
clustering_cv(Orange, repeats = NULL)
53+
Condition
54+
Error in `clustering_cv()`:
55+
! `repeats` must be a single positive integer.
3256

3357
---
3458

tests/testthat/_snaps/form_pred.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# dots
2+
3+
Code
4+
form_pred(y ~ .)
5+
Condition
6+
Error in `terms.formula()`:
7+
! '.' in formula and no 'data' argument
8+
9+
---
10+
11+
Code
12+
form_pred(terms(y ~ .))
13+
Condition
14+
Error in `terms.formula()`:
15+
! '.' in formula and no 'data' argument
16+
17+
---
18+
19+
Code
20+
form_pred(y ~ (.)^2)
21+
Condition
22+
Error in `terms.formula()`:
23+
! '.' in formula and no 'data' argument
24+
25+
---
26+
27+
Code
28+
form_pred(terms(y ~ (.)^2))
29+
Condition
30+
Error in `terms.formula()`:
31+
! '.' in formula and no 'data' argument
32+

tests/testthat/_snaps/labels.md

+34
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,37 @@
66
Error in `labels()`:
77
! `labels` not implemented for nested resampling
88

9+
# adding labels
10+
11+
Code
12+
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits[[1]], 7)
13+
Condition
14+
Error in `add_resample_id()`:
15+
! `dots` should be a single logical.
16+
17+
---
18+
19+
Code
20+
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits[[1]], c(
21+
TRUE, TRUE))
22+
Condition
23+
Error in `add_resample_id()`:
24+
! `dots` should be a single logical.
25+
26+
---
27+
28+
Code
29+
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits)
30+
Condition
31+
Error in `add_resample_id()`:
32+
! `split` should be a single <rset> object.
33+
34+
---
35+
36+
Code
37+
analysis(car_folds$splits[[1]]) %>% as.matrix() %>% add_resample_id(car_folds$
38+
splits[[1]])
39+
Condition
40+
Error in `add_resample_id()`:
41+
! `.data` should be a data frame.
42+

0 commit comments

Comments
 (0)