tests/testthat/test-validate_model.R

context("test-validate_model.R")

test_that("validate_model", {
  # Test expression capturing
  expect_identical(validate_formula(no_specials(user_model)), as.name("user_model"))
  
  # Test formula evaluating
  user_model <- y~x
  expect_identical(validate_formula(no_specials(user_model)), user_model)
  
  # Test bare formula
  expect_identical(validate_formula(no_specials(y~x)), y~x)
  
  tsbl1 <- tsibble::tsibble(
    date = seq(as.Date("2017-01-01"), as.Date("2017-01-10"), by = 1),
    value = rnorm(10), index = date
  )
  
  # Test automatic response selection
  expect_message(res <- validate_formula(no_specials(), data = tsbl1),
                 "Model not specified, defaulting to automatic modelling of the `value` variable.")
  expect_identical(res, as.name("value"))
  
  # Test LHS automatic response selection
  expect_message(res <- validate_formula(no_specials(~x), data = tsbl1), "Model not specified, defaulting to automatic modelling of the `value` variable.")
  expect_identical(res, value ~ x)
  
  # Test failed response selection
  tsbl1[["value2"]] <- rnorm(10) 
  expect_error(validate_formula(no_specials(), data = tsbl1), "Could not automatically determine the response variable")
  
  # Test failed LHS response variable selection
  expect_error(validate_formula(no_specials(~ x), data = tsbl1), "Could not automatically determine the response variable")
  
  # Test not supported automatic variable selection
  expect_error(validate_formula(no_specials(), data = NULL), "This model function does not support automatic selection")
})

Try the fabletools package in your browser

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

fabletools documentation built on Oct. 12, 2023, 1:07 a.m.