tests/testthat/test_cube.R

context("Calculating the cube of non-numerics")

test_that("At least numeric values work.", {
  num_vec <- c(0, -4.6, 3.4)
  expect_identical(cube(num_vec), num_vec^3)
})

test_that("Logicals automatically convert to numeric.", {
  logic_vec <- c(TRUE, TRUE, FALSE)
  expect_identical(cube(logic_vec), logic_vec^3)
})

test_that("At least numeric values work.", {
  chr_vec <- c("how", "are", "you")
  expect_error(cube(chr_vec))
  chr_vec2 <- c("-1", "0", "5")
  expect_error(cube(chr_vec2))
})
bcahn7/STAT547M-hw09-An-Byeongchan documentation built on May 20, 2019, 5:46 p.m.