diff --git a/tests/testthat/_snaps/constructors.md b/tests/testthat/_snaps/constructors.md index cb4da4dc..5c6bf9a1 100644 --- a/tests/testthat/_snaps/constructors.md +++ b/tests/testthat/_snaps/constructors.md @@ -169,6 +169,37 @@ Range (transformed scale): [-10, -1] Values: 2 +--- + + Code + mtry_ish <- mtry() + mtry_ish$label <- NULL + print(mtry_ish) + Message + Quantitative Parameter + Range: [1, ?] + +--- + + Code + fun_ish <- weight_func() + fun_ish$label <- NULL + print(fun_ish) + Message + Qualitative Parameter + 10 possible values include: + 'rectangular', 'triangular', 'epanechnikov', 'biweight', 'triweight', 'cos', + 'inv', 'gaussian', 'rank', and 'optimal' + +--- + + Code + signed_hash() + Message + Signed Hash Value (qualitative) + 2 possible values include: + TRUE and FALSE + # bad ranges Code diff --git a/tests/testthat/_snaps/encode_unit.md b/tests/testthat/_snaps/encode_unit.md index 6c07fa6e..8ef3c3b4 100644 --- a/tests/testthat/_snaps/encode_unit.md +++ b/tests/testthat/_snaps/encode_unit.md @@ -1,3 +1,27 @@ +# to [0, 1] for qualitative values + + Code + encode_unit(prune_method(), "don't prune", direction = "forward") + Condition + Error in `encode_unit()`: + ! Some values are not in the reference set of possible values: "bad_vals"}. + +--- + + Code + encode_unit(prune_method(), 13, direction = "forward") + Condition + Error in `encode_unit()`: + ! `value` should be a character vector. + +# to [0, 1] for quantitative values + + Code + eencode_unit(penalty(), "penalty", direction = "forward") + Condition + Error in `eencode_unit()`: + ! could not find function "eencode_unit" + # bad args Code @@ -95,3 +119,11 @@ Error in `encode_unit()`: ! Values should be on [0, 1]. +--- + + Code + encode_unit(mtry(), 1:2, direction = "backward") + Condition + Error in `encode_unit()`: + ! The parameter object contains unknowns. + diff --git a/tests/testthat/_snaps/grids.md b/tests/testthat/_snaps/grids.md index 09e3e5c4..19da2638 100644 --- a/tests/testthat/_snaps/grids.md +++ b/tests/testthat/_snaps/grids.md @@ -101,3 +101,11 @@ 8 0.00001 1 9 1 1 +# new param grid from conventional data frame + + Code + new_param_grid(as.matrix(x)) + Condition + Error in `new_param_grid()`: + ! `x` must be a data frame to construct a new grid from. + diff --git a/tests/testthat/test-aaa_values.R b/tests/testthat/test-aaa_values.R index ea50ae06..df971a6a 100644 --- a/tests/testthat/test-aaa_values.R +++ b/tests/testthat/test-aaa_values.R @@ -32,6 +32,8 @@ test_that("transforms", { expect_equal( value_transform(mtry(), 1:3), 1:3 ) + expect_false(value_validate(prior_terminal_node_coef(), 0)) + expect_false(value_validate(activation(), "ham")) }) diff --git a/tests/testthat/test-constructors.R b/tests/testthat/test-constructors.R index c330962a..d1ff8b90 100644 --- a/tests/testthat/test-constructors.R +++ b/tests/testthat/test-constructors.R @@ -87,6 +87,20 @@ test_that("printing", { expect_snapshot( value_set(cost_complexity(), log10(c(.09, .0001))) ) + + expect_snapshot({ + mtry_ish <- mtry() + mtry_ish$label <- NULL + print(mtry_ish) + }) + + expect_snapshot({ + fun_ish <- weight_func() + fun_ish$label <- NULL + print(fun_ish) + }) + + expect_snapshot(signed_hash()) }) diff --git a/tests/testthat/test-encode_unit.R b/tests/testthat/test-encode_unit.R index 77a4495f..1f114d2d 100644 --- a/tests/testthat/test-encode_unit.R +++ b/tests/testthat/test-encode_unit.R @@ -7,6 +7,14 @@ test_that("to [0, 1] for qualitative values", { z_back <- encode_unit(z, rev(z_0), direction = "backward") expect_equal(z_back, rev(prune_method()$values)) + expect_snapshot( + error = TRUE, + encode_unit(prune_method(), "don't prune", direction = "forward") + ) + expect_snapshot( + error = TRUE, + encode_unit(prune_method(), 13, direction = "forward") + ) }) @@ -26,6 +34,10 @@ test_that("to [0, 1] for quantitative values", { y_trans <- encode_unit(y, y_0, direction = "backward", original = FALSE) expect_equal(y_orig, 214, tolerance = 0.01) expect_equal(y_trans, log10(214), tolerance = 0.01) + expect_snapshot( + error = TRUE, + eencode_unit(penalty(), "penalty", direction = "forward") + ) }) @@ -98,4 +110,8 @@ test_that("bad args", { error = TRUE, encode_unit(z, 1:2, direction = "backward") ) + expect_snapshot( + error = TRUE, + encode_unit(mtry(), 1:2, direction = "backward") + ) }) diff --git a/tests/testthat/test-grids.R b/tests/testthat/test-grids.R index b860b9b1..781493dd 100644 --- a/tests/testthat/test-grids.R +++ b/tests/testthat/test-grids.R @@ -8,6 +8,10 @@ test_that("regular grid", { nrow(grid_regular(mixture(), trees(), levels = 2)), 4 ) + expect_equal( + nrow(grid_regular(mixture(), trees(), levels = 2, filter = trees == 1)), + 2 + ) expect_equal( nrow(grid_regular(mixture(), trees(), levels = 2:3)), prod(2:3) @@ -56,6 +60,10 @@ test_that("random grid", { nrow(grid_random(prod_degree(), prune_method(), size = 50)), 12 ) + expect_equal( + nrow(grid_random(list(mixture(), trees()), size = 2)), + 2 + ) }) @@ -92,4 +100,11 @@ test_that("new param grid from conventional data frame", { expect_no_condition(y <- dials:::new_param_grid(x)) expect_true(tibble::is_tibble(y)) + + # or from a matrix? + expect_snapshot( + error = TRUE, + new_param_grid(as.matrix(x)) + ) + })