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")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.