Skip to content

Commit

Permalink
add test for parameters.R:89
Browse files Browse the repository at this point in the history
  • Loading branch information
hfrick committed Dec 16, 2024
1 parent 425d6cd commit d84c713
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
15 changes: 12 additions & 3 deletions tests/testthat/_snaps/parameters.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# parameters_const() input checks

Code
parameters_constr(2)
parameters_constr(name = 2)
Condition
Error:
! `name` must be a character vector, not the number 2.
Expand All @@ -10,7 +10,7 @@

Code
ab <- c("a", "b")
parameters_constr(ab, c("a", "a"), ab, ab, ab)
parameters_constr(ab, id = c("a", "a"), ab, ab, ab)
Condition
Error:
x Element id should have unique values.
Expand All @@ -20,11 +20,20 @@

Code
ab <- c("a", "b")
parameters_constr(ab, ab, ab, ab, ab, "not a params list")
parameters_constr(ab, ab, ab, ab, ab, object = "not a params list")
Condition
Error:
! `object` must be a list of <param> objects.

---

Code
ab <- c("a", "b")
parameters_constr(ab, ab, ab, ab, ab, object = list(penalty(), "not a param"))
Condition
Error:
! `object` elements in the following positions must be `NA` or a <param> object: 2.

---

Code
Expand Down
10 changes: 7 additions & 3 deletions tests/testthat/test-parameters.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
test_that("parameters_const() input checks", {
expect_snapshot(error = TRUE, {
parameters_constr(2)
parameters_constr(name = 2)
})
expect_snapshot(error = TRUE, {
ab <- c("a", "b")
parameters_constr(ab, c("a", "a"), ab, ab, ab)
parameters_constr(ab, id = c("a", "a"), ab, ab, ab)
})
expect_snapshot(error = TRUE, {
ab <- c("a", "b")
parameters_constr(ab, ab, ab, ab, ab, "not a params list")
parameters_constr(ab, ab, ab, ab, ab, object = "not a params list")
})
expect_snapshot(error = TRUE, {
ab <- c("a", "b")
parameters_constr(ab, ab, ab, ab, ab, object = list(penalty(), "not a param"))
})
expect_snapshot(error = TRUE, {
ab <- c("a", "b")
Expand Down

0 comments on commit d84c713

Please sign in to comment.