tests/testthat/helper.R

test_accuracy_means_error_handling <- function(.f) {
  test_that("error handling works", {
    a <- 1:10
   b <- 1
   c <- 1:10
   d <- letters[1:10]

   expect_error(
     .f(d, a),
     "`actual` must be numeric; not character.",
     class = "error_argument_type"
   )
   expect_error(
     .f(a, d),
     "`predicted` must be numeric; not character.",
     class = "error_argument_type"
   )
   expect_error(
     .f(a, b),
     "`actual` and `predicted` must have the same length.",
     class = "error_argument_diff_length"
   )
   expect_error(
     .f(a, c, na.rm = "true"),
     "`na.rm` must be logical; not character.",
     class = "error_argument_type"
   )
  })
}

test_accuracy_error_handling <- function(.f) {
  test_that("error handling works", {
    a <- 1:10
   b <- 1
   c <- letters[1:10]

   expect_error(
     .f(c, a),
     "`actual` must be numeric; not character.",
     class = "error_argument_type"
   )
   expect_error(
     .f(a, c),
     "`predicted` must be numeric; not character.",
     class = "error_argument_type"
   )
   expect_error(
     .f(a, b),
     "`actual` and `predicted` must have the same length.",
     class = "error_argument_diff_length"
   )
  })
}

Try the lvmisc package in your browser

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

lvmisc documentation built on April 5, 2021, 5:06 p.m.