tests/testthat/test_as_task.R

test_that("as_task conversion", {
  task = tsk("zoo")
  converted = as_task(task)
  cloned = as_task(task, clone = TRUE)

  expect_class(converted, "Task")
  expect_same_address(task, converted)
  expect_different_address(task, cloned)

  expect_list(as_tasks(task), types = "Task")
  expect_list(as_tasks(list(task)), types = "Task")
})

test_that("as_task_xx error messages (#944)", {
  expect_error(
    as_task_classif(data.frame(x = factor(c("a", "b", "a", "b"), levels = c("a", "b")), y = factor(c("a", "b", "a", "b"), levels = c("a", "b")))),
    "subset of"
  )

  expect_error(
    as_task_regr(data.frame(x = factor(c("a", "b", "a", "b"), levels = c("a", "b")), y = factor(c("a", "b", "a", "b"), levels = c("a", "b")))),
    "subset of"
  )
})

Try the mlr3 package in your browser

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

mlr3 documentation built on Oct. 18, 2024, 5:11 p.m.