tests/testthat/test-sum_squares.R

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)
ischlackow/mypackage3 documentation built on Jan. 8, 2020, 12:05 a.m.