tests/testthat/test-resid.R

context("The function that calculates the residuals")

# In this file we test the resid function

test_that("The function gives reasonable results when used correctly by the user", {
  expect_equal(length(resid(rnorm(2000) + c(rep(4,1000),rep(0,1000)), cpt = 1000, type_chg = "mean", type_res = "raw")),2000)
  expect_equal(length(resid(rnorm(1000), cpt = 0, type_chg = "mean", type_res = "standardised")),1000)
})

test_that("The function gives error messages whenever the input argument is meaningless", {
  # The input for x is a character string.
  expect_error(resid(x = "I am not a numeric vector"))
  
  # The input for x contains NA
  expect_error(resid(x = c(rnorm(100),NA)))
})

Try the IDetect package in your browser

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

IDetect documentation built on May 7, 2026, 5:09 p.m.