tests/testthat/test_Context.R

test_that("Context", {
  ContextTest = R6::R6Class("ContextTest",
    inherit = Context,
    public = list(

      table = NULL,

      initialize = function(table) {
        super$initialize(id = "test", label = "Context Test")
        self$table = table
      }
    ),

    active = list(
      data = function(rhs) {
        if (missing(rhs)) {
          self$table
        } else {
          self$table = rhs
        }
      }
    )
  )
  table = data.table::data.table(x1 = runif(10))
  test = ContextTest$new(table)

  expect_output(print(test), "data")
  expect_string(test$label, "Context Test")
  expect_string(test$id, "test")
  expect_data_table(test$data)
})

Try the mlr3misc package in your browser

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

mlr3misc documentation built on Sept. 20, 2023, 5:06 p.m.