Skip to content

Commit

Permalink
more missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo committed Oct 30, 2024
1 parent 2ff5c24 commit bf4e1cf
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/testthat/_snaps/constructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/encode_unit.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.

8 changes: 8 additions & 0 deletions tests/testthat/_snaps/grids.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

2 changes: 2 additions & 0 deletions tests/testthat/test-aaa_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})


Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-constructors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})


Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-encode_unit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
})


Expand All @@ -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")
)
})


Expand Down Expand Up @@ -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")
)
})
15 changes: 15 additions & 0 deletions tests/testthat/test-grids.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
})


Expand Down Expand Up @@ -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))
)

})

0 comments on commit bf4e1cf

Please sign in to comment.