tests/testthat/test_convert_to_written.R

library(rutilities)
library(tibble)
context("Converting a vector to a written string")

test_that("Applying function to non-character throws error",{
    expect_error(convert_to_written(c(1,2)),
                 "Class must be character")
    expect_error(convert_to_written(c(TRUE, FALSE)),
                 "Class must be character")
    expect_error(convert_to_written(c(~x, ~y)),
                 "Class must be character")
})

test_that("Applying function to character vector of length zero throws error",{
    expect_error(convert_to_written(character(0)),
                 "Character vector must contain non-NA elements")
})

vec_in <- c("a", "b", "c", "d")

test_that("Applying function to positive-length character vectors works",{
    expect_identical(convert_to_written(vec_in[1]), "a")
    expect_identical(convert_to_written(vec_in[1:2]), "a and b")
    expect_identical(convert_to_written(vec_in[1:3]), "a, b and c")
    expect_identical(convert_to_written(vec_in[1:4]), "a, b, c and d")
})
andrewjpfeiffer/rutilities documentation built on May 11, 2019, 6:26 p.m.