1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| Rcpp::sourceCpp("checkValue.cpp") testFunc(sample.int(10, 5)) testFunc(rnorm(5))
expect_error(testFunc(c(TRUE, FALSE)), "Not supported type!")
expect_error(testFunc(c(sample.int(10, 3), NA_integer_)), "x must not contain NA!")
expect_error(testFunc(c(rnorm(3), NA_real_)), "x must not contain NA, NaN or Inf!") expect_error(testFunc(c(rnorm(3), NaN)), "x must not contain NA, NaN or Inf!") expect_error(testFunc(c(rnorm(3), Inf)), "x must not contain NA, NaN or Inf!")
library(testthat)
checkValue(c(1, 2), "x", 14, 2) checkValue(c(1L, 2L), "x", 13, 2) checkValue(c(TRUE, FALSE), "x", 10, 2) checkValue(c("1", "2"), "x", 16, 2)
expect_error(checkValue(c(1, 2), "x", 14, 1), "The length of x must be 1!") expect_error(checkValue(c(1, 2), "x", 14, 3), "The length of x must be 3!")
expect_error(checkValue(c(1, 2), "x", 13, 2), "x must be integer type!")
expect_error(checkValue(c(1, NA_real_), "x", 14, 2), "x must not contain NA, NaN or Inf!") expect_error(checkValue(c(1, NaN), "x", 14, 2), "x must not contain NA, NaN or Inf!") expect_error(checkValue(c(1, Inf), "x", 14, 2), "x must not contain NA, NaN or Inf!") expect_error(checkValue(c(1, -Inf), "x", 14, 2), "x must not contain NA, NaN or Inf!")
expect_error(checkValue(c(TRUE, NA), "x", 10, 2), "x must not contain NA.") expect_error(checkValue(c(1L, NA_integer_), "x", 13, 2), "x must not contain NA.") expect_error(checkValue(c("1", NA_character_), "x", 16, 2), "x must not contain NA.")
expect_error(checkValue(complex(2, 1:2, 0:1), "x", 14, 2), "x must be double type!") expect_error(checkValue(complex(2, c(1, NA), 0:1), "x", 15, 2), "x must not contain NA, NaN or Inf!") expect_error(checkValue(complex(2, c(1, NaN), 0:1), "x", 15, 2), "x must not contain NA, NaN or Inf!") expect_error(checkValue(complex(2, c(1, Inf), 0:1), "x", 15, 2), "x must not contain NA, NaN or Inf!")
|