tests/testthat/test_hello_world_function.r

context("Testing hello_world_function")

test_that("Returns expected string when name is null", {
  ss <- hello_world_function()
  expect_equal(ss, 'Hello World')
})

test_that("Returns expected string when name is not null", {
  ss <- hello_world_function('Trevor')
  expect_equal(ss, 'Hello Trevor')
})

test_that("Error messages are working properly",{
  testthat::expect_error(hello_world_function(NA)
                         , "The name is NA. Need to know who to say hello to.")

  testthat::expect_error(hello_world_function(2)
                         , "The name must be a character")

  testthat::expect_error(hello_world_function(c('Trevor','Trevor'))
                         , "The name must only be of length 1.")


})
ArithmeticR/TOmisc documentation built on May 14, 2019, 12:43 p.m.