tests/testthat/test-sum_squares.R

test_that("multiplication works", {
  expect_equal(2 * 2, 4)
})

test_vec <- rnorm(20, mean = 5, sd = 1.2)

### Standard case
# Expect a floating point result from a nuemeric 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) #greater than
})

### Special cases
# Expect that the result is
test_that("Identicial values give a sum of squares of zero", {
  expect_equal(sum_squares(rep(1,10)),0)
})

### Expected failures
# Expect that the result is NA
test_that("Output is not NA", {
  expect_equal(sum_squares(NA), NA_real_)
})

# Character inputs
test_that("Non numeric input gives errors and/or warnings", {
  expect_condition(sum_squares(c("cat", "dog")))
})

# #Empty vector
# test_that("When an empty vector is supplied, error is returned", {
#   expect_error(sum_squares(c()))
# })
JoWatson2011/mypackage documentation built on Jan. 8, 2020, 12:02 a.m.