tests/testthat/test-normcheck-engine.R

test_that("normcheck keeps the base graphics engine as the default", {
  values = c(-2, -1, 0, 1, 2)

  pdf(NULL)
  on.exit(dev.off(), add = TRUE)

  expect_silent(normcheck(values))
  expect_silent(normcheck(values, engine = "base"))
})


test_that("normcheck validates the plotting engine argument", {
  values = c(-2, -1, 0, 1, 2)

  expect_error(
    normcheck(values, engine = "lattice"),
    "'arg' should be one of",
    fixed = TRUE
  )
})


test_that("normcheck ggplot2 engine returns ggplot objects when available", {
  skip_if_not_installed("ggplot2")

  values = c(-2, -1, 0, 1, 2)

  qqPlot = normcheck(values, engine = "ggplot2", whichPlot = 1)
  bothPlots = normcheck(values, engine = "ggplot2", whichPlot = 1:2)

  expect_s3_class(qqPlot, "ggplot")
  expect_s3_class(bothPlots, "s20xNormcheck_ggplot2")
  expect_length(bothPlots, 2)
})


test_that("normcheck lm method passes engine and bootstrap arguments", {
  skip_if_not_installed("ggplot2")

  sampleData = data.frame(
    response = c(1, 2, 3, 4, 5),
    predictor = c(1, 2, 3, 4, 5)
  )
  fit = lm(response ~ predictor, data = sampleData)

  plotObject = normcheck(fit, engine = "ggplot2", whichPlot = 1, bootstrap = TRUE, B = 1)

  expect_s3_class(plotObject, "ggplot")
})


test_that("normcheck ggplot2 engine uses a base-like theme", {
  skip_if_not_installed("ggplot2")

  values = c(-2, -1, 0, 1, 2)

  bothPlots = normcheck(values, engine = "ggplot2", whichPlot = 1:2)

  expect_true(inherits(bothPlots$qq$theme$panel.grid.major, "element_blank"))
  expect_true(inherits(bothPlots$histogram$theme$panel.grid.major, "element_blank"))
})

Try the s20x package in your browser

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

s20x documentation built on July 1, 2026, 9:06 a.m.