tests/testthat/test_ContextEvaluation.R

test_that("ContextResample works", {
  task = tsk("pima")
  learner = lrn("classif.rpart")
  resampling = rsmp("cv", folds = 3)
  iteration = 1

  ctx = ContextResample$new(task, learner, resampling, iteration)

  expect_task(ctx$task)
  expect_learner(ctx$learner)
  expect_resampling(ctx$resampling)
  expect_equal(ctx$iteration, iteration)

  expect_error(
    {
      ctx$task = tsk("spam")
    },
    "read-only"
  )
  expect_error(
    {
      ctx$resampling = rsmp("cv", folds = 5)
    },
    "read-only"
  )
  expect_error(
    {
      ctx$iteration = 2
    },
    "read-only"
  )
})

Try the mlr3 package in your browser

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

mlr3 documentation built on June 11, 2026, 5:08 p.m.