Add test files in testthat folder, the names should starts with test
test for equality
- expect_equal(), check for equality within a numerical tolerance
- expect_identical(), test for exact equivalence
- expect_true, test for logic true
- expect_equivalent, ignores attributes
- skip(), skip a test
# test_getRand.R
context("Test functions in getRand.R ...")
library(myPackage)
test_that("test getRand ...", {
set.seed(42)
expect_equal(getRand(1), 0.914806, tolerance = .0001)
expect_equal(getRand(2), c(0.9370754, 0.2861395), tolerance = 0.0001);
})
test_that("test getRandN ...", {
expect_equal(getRandN(1, 2), 1.660895, tolerance = 0.0001)
})
# test_getHello.R
context("Test functions in getHello.R ...")
library(myPackage)
test_that("test getHello ...", {
expect_identical(getHello(), "Hello World!")
})