Skip to content

Commit

Permalink
Merge fa2717d into 62ff25a
Browse files Browse the repository at this point in the history
  • Loading branch information
mb706 committed Feb 7, 2019
2 parents 62ff25a + fa2717d commit 7d55ca3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/ParamSetCollection.R
Expand Up @@ -44,7 +44,7 @@ ParamSetCollection = R6Class("ParamSetCollection", inherit = ParamSet,
private$.params = list()
# clone each param into new params-list and prefix id
ps_all = lapply(private$.sets, function(s) {
ss = s$clone()
ss = s$clone(deep = TRUE)
ps = ss$params
set_names(ps, paste(s$set_id, names(ps), sep = "."))
})
Expand Down
36 changes: 36 additions & 0 deletions tests/testthat/test_ParamSetCollection.R
@@ -1,12 +1,16 @@
context("ParamSetCollection")

test_that("simple active bindings work", {

ps1 = th_paramset_dbl1()
ps1$set_id = "s1"
ps2 = th_paramset_full()
ps2$set_id = "s2"
psc = ParamSetCollection$new(list(ps1, ps2))

ps1clone = ps1$clone(deep = TRUE)
ps2clone = ps2$clone(deep = TRUE)

my_c = function(xs1, xs2) { # littler helper to join to ps-result and prefix names
ns = c(paste0("s1.", names(xs1)), paste0("s2.", names(xs2)))
set_names(c(xs1, xs2), ns)
Expand Down Expand Up @@ -48,10 +52,22 @@ test_that("simple active bindings work", {
expect_names(names(x), permutation.of = psc$ids())
expect_equal(x$s2.th_param_int, 99)
}

# ps1 and ps2 should not be changed
expect_equal(ps1, ps1clone)
expect_equal(ps2, ps2clone)

expect_output(print(psc), "s1\\.th_param_dbl.*s2\\.th_param_int.*s2\\.th_param_dbl.*s2\\.th_param_fct.*s2\\.th_param_lgl.*")

# ps1 and ps2 should not be changed by printing
expect_equal(ps1, ps1clone)
expect_equal(ps2, ps2clone)

})


test_that("some operations are not allowed", {

ps1 = th_paramset_dbl1()
ps1$set_id = "s1"
ps2 = th_paramset_full()
Expand All @@ -64,6 +80,7 @@ test_that("some operations are not allowed", {
})

test_that("deps", {

ps1 = ParamSet$new(list(
ParamFct$new("f", values = c("a", "b")),
ParamDbl$new("d")
Expand All @@ -76,6 +93,10 @@ test_that("deps", {
ParamDbl$new("d")
))
ps2$set_id = "ps2"

ps1clone = ps1$clone(deep = TRUE)
ps2clone = ps2$clone(deep = TRUE)

psc = ParamSetCollection$new(list(ps1, ps2))
d = psc$deps
expect_data_table(d, nrows = 1, ncols = 3)
Expand All @@ -86,9 +107,14 @@ test_that("deps", {
expect_data_table(psc$deps, nrows = 2, ncols = 3)
expect_true(psc$check(list(ps1.f = "a", ps1.d = 0, ps2.d = 0)))
expect_string(psc$check(list(ps2.d = 0)))

# ps1 and ps2 should not be changed
expect_equal(ps1clone, ps1)
expect_equal(ps2clone, ps2)
})

test_that("param_vals", {

ps1 = ParamSet$new(list(
ParamFct$new("f", values = c("a", "b")),
ParamDbl$new("d", lower = 1, upper = 8)
Expand All @@ -99,6 +125,10 @@ test_that("param_vals", {
ParamDbl$new("d", lower = 1, upper = 8)
))
ps2$set_id = "bar"

ps1clone = ps1$clone(deep = TRUE)
ps2clone = ps2$clone(deep = TRUE)

pcs = ParamSetCollection$new(list(ps1, ps2))
expect_equal(pcs$param_vals, list())
ps2$param_vals = list(d = 3)
Expand All @@ -107,4 +137,10 @@ test_that("param_vals", {
expect_equal(pcs$param_vals, list(foo.d = 8))
expect_equal(ps1$param_vals, list(d = 8))
expect_equal(ps2$param_vals, set_names(list(), character(0)))

ps1clone$param_vals$d = 8
ps2$param_vals = list()
expect_equal(ps1clone, ps1)
expect_equal(ps2clone, ps2)

})

0 comments on commit 7d55ca3

Please sign in to comment.