tests/testthat/test-all_real.R

context("test-all_real")

test_that("all_real works for NaN and Inf", {

  x <- c(1, 2, 3, NA, 5, NaN, Inf)

  expect_false(all_real(x))

  y <- c(1, 2, 3, 4, 5, 6, 7)

  expect_true(all_real(y))
})

test_that("all_real works for NaN, Inf and NA", {

  x <- c(1, 2, 3, NA, 5, NaN, Inf)

  expect_false(all_real(x, include_na = TRUE))

  y <- c(1, 2, 3, 4, 5, 6, NA)

  expect_false(all_real(y, include_na = TRUE))
})


test_that("all_real returns errors", {

  x <- matrix(c(1, 2, 3, NA, 5, NaN), ncol = 2)

  expect_error(all_real(x),
               regexp = "input must be a vector.")

  y <- c("A", "B", "C", NA, "E", NaN, Inf)

  expect_error(all_real(y),
               regexp = "input must be of class 'numeric'.")
})
mhesselbarth/UtilityFunctions documentation built on April 8, 2024, 9:38 a.m.