Skip to content

Commit

Permalink
add tests for parameters.R
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Sep 20, 2024
1 parent 0f5f2df commit 7f83d3d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
x Element id should have unique values.
i Duplicates exist for item: a

---

Code
parameters(list(a = mtry, a = penalty()))
Condition
Error in `parameters()`:
! The objects should all be <param> objects.

# updating

Code
Expand All @@ -68,6 +76,14 @@
Error in `update()`:
! At least one parameter is not a dials parameter object or NA: penalty.

---

Code
update(p_1, not_penalty = 1:2)
Condition
Error in `update()`:
! At least one parameter does not match any id's in the set: not_penalty.

---

Code
Expand All @@ -76,6 +92,14 @@
Error in `update()`:
! All arguments should be named.

---

Code
update(p_1)
Condition
Error in `update()`:
! Please supply at least one parameter object.

# printing

Code
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ test_that("create from lists of param objects", {
expect_equal(p_3$id, c("a", "some name"))

expect_snapshot(error = TRUE, parameters(list(a = mtry(), a = penalty())))
expect_snapshot(error = TRUE, parameters(list(a = mtry, a = penalty())))
})

test_that("updating", {
Expand All @@ -61,8 +62,10 @@ test_that("updating", {

expect_snapshot(error = TRUE, update(p_1, new_pen))
expect_snapshot(error = TRUE, update(p_1, penalty = 1:2))
expect_snapshot(error = TRUE, update(p_1, not_penalty = 1:2))
expect_snapshot(error = TRUE, update(p_1, penalty(), mtry = mtry(3:4)))
expect_error(update(p_1, penalty = NA), NA)
expect_snapshot(error = TRUE, update(p_1))
})

test_that("printing", {
Expand Down

0 comments on commit 7f83d3d

Please sign in to comment.