File: test_base_helpers.R

package info (click to toggle)
r-cran-mlr 2.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,392 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (47 lines) | stat: -rwxr-xr-x 1,331 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

test_that("makeOptPathDFFromMeasures", {
  measures = list(mae, auc)
  par.set = makeParamSet(
    makeIntegerParam("a"),
    makeIntegerParam("b")
  )
  opt.path = makeOptPathDFFromMeasures(par.set, measures)
  addOptPathEl(opt.path, x = list(1L, 1L), y = c(0.5, 0.5))
  res = getOptPathEl(opt.path, 1L)
  supposed.names = sapply(measures, function(m) paste(m$id, m$aggr$id, sep = "."))
  expect_equal(names(res$y), supposed.names)
})

test_that("propVectorToMatrix", {
  x = seq(0, 1, length.out = 11)
  levs = LETTERS[1:2]
  m = propVectorToMatrix(x, levs)
  expect_equal(m[, 1], 1 - x)
  expect_equal(m[, 2], x)
  expect_equal(colnames(m), levs)
})

test_that("listTaskTypes", {
  expected = c("classif", "regr", "surv", "costsens", "cluster", "multilabel")
  expect_equal(expected, listTaskTypes())
})

test_that("listLearnerProperties", {
  expected = c("classif", "regr", "surv", "costsens", "cluster", "multilabel")
  expect_equal(expected, listTaskTypes())
})


test_that("suppressWarning works", {
  foo = function(x) {
    if (x > 3) {
      warning("x is pretty large.")
    }
    x
  }

  expect_equal(suppressWarning(foo(3), "pretty"), 3)
  expect_equal(suppressWarning(foo(3), "<nomatch>"), 3)
  expect_equal(suppressWarning(foo(4), "pretty"), 4)
  expect_warning(suppressWarning(foo(4), "<nomatch>"), "pretty")
})