test_vec <- rnorm(20, mean = 5, sd = 1.2)
### Standard case
# Expect a floating point result from a numeric input
test_that("Output is type \"double\" for numeric input", {
expect_type(sum_squares(test_vec), "double")
})
# Expect that the result is not negative
test_that("Output is non-negative", {
expect_gte(sum_squares(test_vec), 0)
})
test_identical <- rep(1, 100)
test_that("Output of a constant vector is 0", {
expect_equal(sum_squares(test_identical), 0)
})
test_that("Non-numeric input", {
expect_condition(sum_squares(c("a", "b", "c")))
})
test_that("Missing values give a result of NA", {
expect_equal(sum_squares(c(test_vec, NA)), NA_real_)
})
test_that("Empty input does not give a warning / error", {
expect_condition(sum_squares(c()))
})
#expect_error(code, regexp)
#expect_warning(code, regexp)
#expect_warning(code, NA)
#expect_known_output(code)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.