From 7f83d3d842ad1c8c6b9757a2f3b1f38e512cd404 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Fri, 20 Sep 2024 11:15:23 -0700 Subject: [PATCH] add tests for parameters.R --- tests/testthat/_snaps/parameters.md | 24 ++++++++++++++++++++++++ tests/testthat/test-parameters.R | 3 +++ 2 files changed, 27 insertions(+) diff --git a/tests/testthat/_snaps/parameters.md b/tests/testthat/_snaps/parameters.md index 1404eeca..5e84bdf6 100644 --- a/tests/testthat/_snaps/parameters.md +++ b/tests/testthat/_snaps/parameters.md @@ -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 objects. + # updating Code @@ -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 @@ -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 diff --git a/tests/testthat/test-parameters.R b/tests/testthat/test-parameters.R index b93aa5a2..aa4b6953 100644 --- a/tests/testthat/test-parameters.R +++ b/tests/testthat/test-parameters.R @@ -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", { @@ -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", {