tests/testthat/test_getParamTypes.R

context("getParamTypes")

test_that("getParamTypes", {
  ps = makeParamSet(
    makeDiscreteParam("x", values = c("a", "b")),
    makeNumericVectorParam("y", len = 2),
    makeIntegerParam("z"),
    makeCharacterVectorParam("s", len = 2)
  )

  expect_equal(
    getParamTypes(ps, df.cols = FALSE, use.names = FALSE),
    c("discrete", "numericvector", "integer", "charactervector")
  )
  expect_equal(
    getParamTypes(ps, df.cols = TRUE, use.names = FALSE),
    c("factor", "numeric", "numeric", "integer", "character", "character")
  )
  expect_equal(
    getParamTypes(ps, df.cols = FALSE, use.names = TRUE),
    c(x = "discrete", y = "numericvector", z = "integer", s = "charactervector")
  )
  expect_equal(
    getParamTypes(ps, df.cols = TRUE, use.names = TRUE, with.nr = FALSE),
    c(x = "factor", y = "numeric", y = "numeric", z = "integer", s = "character",
      s = "character")
  )
  expect_equal(
    getParamTypes(ps, df.cols = TRUE, use.names = TRUE, with.nr = TRUE),
    c(x = "factor", y1 = "numeric", y2 = "numeric", z = "integer",
      s1 = "character", s2 = "character")
  )

  expect_equal(
    getParamTypes(makeParamSet()),
    character(0L)
  )
})

Try the ParamHelpers package in your browser

Any scripts or data that you put into this service are public.

ParamHelpers documentation built on March 26, 2020, 7:40 p.m.