tests/testthat/test-validation.R

test_that("validate_varnames works correctly", {
  expect_error(
    validate_varnames(c("hello", "there"), c("hello", "tHeRe")),
    regexp = "Modeling data and prediction data have differing names"
  )
  expect_null(validate_varnames(c("hello", "there"), c("hello", "there")))
})

test_that("validate_data works correctly", {
  expect_error(
    validate_data(mpg ~ ., x = mtcars),
    "Both a formula and data must be supplied"
  )
  expect_error(
    validate_data(mpg ~ ., as.matrix(mtcars)),
    "Argument `data` must be an object with class `data.frame`"
  )
  expect_error(
    validate_data(x = mtcars[, -1], y = mtcars[, 1]),
    "`x` must be of class `matrix` or `sparseMatrix`"
  )
  expect_null(
    validate_data(mpg ~ ., data = mtcars)
  )
})

Try the bolasso package in your browser

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

bolasso documentation built on April 3, 2025, 8:45 p.m.