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)
})
mlr-org/mlr3misc documentation built on April 28, 2024, 11 p.m.