Skip to content

Commit

Permalink
Merge pull request #268 from tidymodels/missing-snapshots
Browse files Browse the repository at this point in the history
Missing snapshots
  • Loading branch information
hfrick authored Oct 23, 2024
2 parents 16ec884 + b127813 commit 78cf6d0
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/blueprint-formula-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# `levels` argument is validated

Code
new_default_formula_blueprint(levels = 1)
Condition
Error in `new_default_formula_blueprint()`:
! `levels` must be a list, not the number 1.

---

Code
new_default_formula_blueprint(levels = list(1))
Condition
Error in `new_default_formula_blueprint()`:
! `levels` must be fully named.

---

Code
new_default_formula_blueprint(levels = list(a = 1))
Condition
Error in `new_default_formula_blueprint()`:
! `levels` must only contain character vectors.

49 changes: 49 additions & 0 deletions tests/testthat/_snaps/blueprint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# check on input to `new_blueprint()`

Code
new_blueprint(same_new_arg = 1, same_new_arg = 2)
Condition
Error in `new_blueprint()`:
! All elements of `...` must have unique names.

# checks for updating a blueprint

Code
update_blueprint(blueprint, intercept = TRUE, intercept = FALSE)
Condition
Error in `update_blueprint()`:
! `...` must have unique names.

---

Code
update_blueprint(blueprint, intercpt = TRUE)
Condition
Error in `update_blueprint()`:
! All elements of `...` must already exist.
i The following fields are new: "intercpt".

# checks the ptype

Code
new_blueprint(ptypes = list(x = 1))
Condition
Error in `new_blueprint()`:
! `ptypes` must have an element named "predictors".

---

Code
new_blueprint(ptypes = list(predictors = "not a tibble", outcomes = "not a tibble"))
Condition
Error in `new_blueprint()`:
! `ptypes$predictors` must be a tibble, not the string "not a tibble".

---

Code
new_blueprint(ptypes = list(predictors = tibble_too_long, outcomes = tibble_too_long))
Condition
Error in `new_blueprint()`:
! `ptypes$predictors` must be size 0, not size 1.

38 changes: 38 additions & 0 deletions tests/testthat/_snaps/model-matrix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `contr_one_hot()` input checks

Code
contr_one_hot(n = 1, sparse = TRUE)
Condition
Warning:
`sparse = TRUE` not implemented for `contr_one_hot()`.
Output
1
1 1

---

Code
contr_one_hot(n = 1, contrasts = FALSE)
Condition
Warning:
`contrasts = FALSE` not implemented for `contr_one_hot()`.
Output
1
1 1

---

Code
contr_one_hot(n = 1:2)
Condition
Error in `contr_one_hot()`:
! `n` must have length 1 when an integer is provided.

---

Code
contr_one_hot(n = list(1:2))
Condition
Error in `contr_one_hot()`:
! `n` must be a character vector or an integer of size 1.

11 changes: 11 additions & 0 deletions tests/testthat/test-blueprint-formula-default.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("`levels` argument is validated", {
expect_snapshot(error = TRUE, {
new_default_formula_blueprint(levels = 1)
})
expect_snapshot(error = TRUE, {
new_default_formula_blueprint(levels = list(1))
})
expect_snapshot(error = TRUE, {
new_default_formula_blueprint(levels = list("a" = 1))
})
})
30 changes: 30 additions & 0 deletions tests/testthat/test-blueprint.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
test_that("check on input to `new_blueprint()`", {
expect_snapshot(error = TRUE, {
new_blueprint(same_new_arg = 1, same_new_arg = 2)
})
})

test_that("checks for updating a blueprint", {
blueprint <- default_xy_blueprint()

expect_snapshot(error = TRUE, {
update_blueprint(blueprint, intercept = TRUE, intercept = FALSE)
})
expect_snapshot(error = TRUE, {
update_blueprint(blueprint, intercpt = TRUE)
})
})

test_that("checks the ptype", {
expect_snapshot(error = TRUE, {
new_blueprint(ptypes = list(x = 1))
})
expect_snapshot(error = TRUE, {
new_blueprint(ptypes = list("predictors" = "not a tibble", outcomes = "not a tibble"))
})

tibble_too_long <- tibble::tibble(x =1)
expect_snapshot(error = TRUE, {
new_blueprint(ptypes = list("predictors" = tibble_too_long, outcomes = tibble_too_long))
})
})
11 changes: 11 additions & 0 deletions tests/testthat/test-model-matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ test_that("`model_matrix()` strips all attributes from the `model.matrix()` resu
# attached "assign" and "contrasts" attributes here
expect_identical(matrix$Speciessetosa, expect)
})

test_that("`contr_one_hot()` input checks", {
expect_snapshot(contr_one_hot(n = 1, sparse = TRUE))
expect_snapshot(contr_one_hot(n = 1, contrasts = FALSE))
expect_snapshot(error = TRUE, {
contr_one_hot(n = 1:2)
})
expect_snapshot(error = TRUE, {
contr_one_hot(n = list(1:2))
})
})

0 comments on commit 78cf6d0

Please sign in to comment.