Skip to content

Commit

Permalink
Merge pull request #538 from tidymodels/use-snapshot-tests
Browse files Browse the repository at this point in the history
Use snapshot tests
  • Loading branch information
hfrick authored Sep 19, 2024
2 parents 77fc1fe + 23200c5 commit bdf12e1
Show file tree
Hide file tree
Showing 34 changed files with 1,305 additions and 203 deletions.
17 changes: 17 additions & 0 deletions tests/testthat/_snaps/boot.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@

# bad args

Code
bootstraps(warpbreaks, strata = warpbreaks$tension)
Condition
Error in `bootstraps()`:
! Can't select columns that don't exist.
x Columns `L`, `L`, `L`, `L`, `L`, etc. don't exist.

---

Code
bootstraps(warpbreaks, strata = c("tension", "wool"))
Condition
Error in `strata_check()`:
! `strata` should be a single name or character value.

---

Code
group_bootstraps(warpbreaks, tension)
Condition
Expand Down
191 changes: 191 additions & 0 deletions tests/testthat/_snaps/bootci.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,194 @@
Error in `bca_calc()`:
! All statistics have missing values.

# Sufficient replications needed to sufficiently reduce Monte Carlo sampling Error for BCa method

Code
int_pctl(bt_small, stats)
Condition
Warning:
Recommend at least 1000 non-missing bootstrap resamples for term `mean`.
Output
# A tibble: 1 x 6
term .lower .estimate .upper .alpha .method
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
1 mean 9.97 10.0 10.1 0.05 percentile

---

Code
int_t(bt_small, stats)
Condition
Warning:
Recommend at least 500 non-missing bootstrap resamples for term `mean`.
Output
# A tibble: 1 x 6
term .lower .estimate .upper .alpha .method
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
1 mean 9.96 10.0 10.1 0.05 student-t

---

Code
int_bca(bt_small, stats, .fn = get_stats)
Condition
Warning:
Recommend at least 1000 non-missing bootstrap resamples for term `mean`.
Output
# A tibble: 1 x 6
term .lower .estimate .upper .alpha .method
<chr> <dbl> <dbl> <dbl> <dbl> <chr>
1 mean 9.96 10.0 10.1 0.05 BCa

# bad input

Code
int_pctl(bt_small, id)
Condition
Error in `check_tidy()`:
! {.arg statistics} should select a list column of tidy results.

---

Code
int_pctl(bt_small, junk)
Condition
Error in `check_tidy()`:
! {.arg statistics} should select a list column of tidy results.

---

Code
int_pctl(bt_small, stats, alpha = c(0.05, 0.2))
Condition
Error in `int_pctl()`:
! `alpha` must be a single numeric value.

---

Code
int_t(bt_small, stats, alpha = "potato")
Condition
Error in `int_t()`:
! `alpha` must be a single numeric value.

---

Code
int_bca(bt_small, stats, alpha = 1:2, .fn = get_stats)
Condition
Error in `int_bca()`:
! `alpha` must be a single numeric value.

---

Code
int_pctl(vfold_cv(mtcars))
Condition
Error in `UseMethod()`:
! no applicable method for 'int_pctl' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"

---

Code
int_t(vfold_cv(mtcars))
Condition
Error in `UseMethod()`:
! no applicable method for 'int_t' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"

---

Code
int_bca(vfold_cv(mtcars))
Condition
Error in `UseMethod()`:
! no applicable method for 'int_bca' applied to an object of class "c('vfold_cv', 'rset', 'tbl_df', 'tbl', 'data.frame')"

---

Code
int_t(bad_bt_norm, stats)
Condition
Error in `check_tidy_names()`:
! `statistics` should select a single column for the standard error.

---

Code
int_bca(bt_norm, stats, .fn = no_dots)
Condition
Error in `has_dots()`:
! `.fn` must have an argument `...`.

---

Code
int_pctl(as.data.frame(bt_norm), stats)
Condition
Error in `UseMethod()`:
! no applicable method for 'int_pctl' applied to an object of class "data.frame"

---

Code
int_t(as.data.frame(bt_norm), stats)
Condition
Error in `UseMethod()`:
! no applicable method for 'int_t' applied to an object of class "data.frame"

---

Code
int_bca(as.data.frame(bt_norm), stats, .fn = get_stats)
Condition
Error in `UseMethod()`:
! no applicable method for 'int_bca' applied to an object of class "data.frame"

---

Code
int_t(bt_norm %>% dplyr::filter(id != "Apparent"), stats)
Condition
Error in `UseMethod()`:
! no applicable method for 'int_t' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

---

Code
int_bca(bt_norm %>% dplyr::filter(id != "Apparent"), stats, .fn = get_stats)
Condition
Error in `UseMethod()`:
! no applicable method for 'int_bca' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

---

Code
int_pctl(badder_bt_norm, bad_term)
Condition
Error in `check_tidy_names()`:
! The tibble in `statistics` should have columns for 'estimate' and 'term'.

---

Code
int_t(badder_bt_norm, bad_err)
Condition
Error in `check_tidy_names()`:
! `statistics` should select a single column for the standard error.

---

Code
int_bca(badder_bt_norm, bad_est, .fn = get_stats)
Condition
Error in `check_tidy_names()`:
! The tibble in `statistics` should have columns for 'estimate' and 'term'.

---

Code
int_pctl(badder_bt_norm, bad_num)
Condition
Error in `pctl_single()`:
! `stats` must be a numeric vector.

36 changes: 30 additions & 6 deletions tests/testthat/_snaps/clustering.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
# bad args

`vars` is required and must contain at least one variable in `data`.
Code
clustering_cv(dat1)
Condition
Error in `clustering_cv()`:
! `vars` is required and must contain at least one variable in `data`.

---

`v` must be a single positive integer greater than 1.
Code
clustering_cv(iris, Sepal.Length, v = -500)
Condition
Error in `clustering_cv()`:
! `v` must be a single positive integer greater than 1.

---

The number of rows is less than `v` = 500.
Code
clustering_cv(iris, Sepal.Length, v = 500)
Condition
Error in `clustering_cv()`:
! The number of rows is less than `v` = 500.

---

`cluster_function` must be one of "kmeans" or "hclust", not "not an option".
Code
clustering_cv(iris, Sepal.Length, cluster_function = "not an option")
Condition
Error in `clustering_cv()`:
! `cluster_function` must be one of "kmeans" or "hclust", not "not an option".

---

Expand All @@ -24,11 +40,19 @@

---

`repeats` must be a single positive integer.
Code
clustering_cv(Orange, repeats = 0)
Condition
Error in `clustering_cv()`:
! `repeats` must be a single positive integer.

---

`repeats` must be a single positive integer.
Code
clustering_cv(Orange, repeats = NULL)
Condition
Error in `clustering_cv()`:
! `repeats` must be a single positive integer.

---

Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/form_pred.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# dots

Code
form_pred(y ~ .)
Condition
Error in `terms.formula()`:
! '.' in formula and no 'data' argument

---

Code
form_pred(terms(y ~ .))
Condition
Error in `terms.formula()`:
! '.' in formula and no 'data' argument

---

Code
form_pred(y ~ (.)^2)
Condition
Error in `terms.formula()`:
! '.' in formula and no 'data' argument

---

Code
form_pred(terms(y ~ (.)^2))
Condition
Error in `terms.formula()`:
! '.' in formula and no 'data' argument

34 changes: 34 additions & 0 deletions tests/testthat/_snaps/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,37 @@
Error in `labels()`:
! `labels` not implemented for nested resampling

# adding labels

Code
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits[[1]], 7)
Condition
Error in `add_resample_id()`:
! `dots` should be a single logical.

---

Code
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits[[1]], c(
TRUE, TRUE))
Condition
Error in `add_resample_id()`:
! `dots` should be a single logical.

---

Code
analysis(car_folds$splits[[1]]) %>% add_resample_id(car_folds$splits)
Condition
Error in `add_resample_id()`:
! `split` should be a single <rset> object.

---

Code
analysis(car_folds$splits[[1]]) %>% as.matrix() %>% add_resample_id(car_folds$
splits[[1]])
Condition
Error in `add_resample_id()`:
! `.data` should be a data frame.

Loading

0 comments on commit bdf12e1

Please sign in to comment.