tests/testthat/test-switchv.R

context("vectorized switch")

test_that("switchv works for strings", {

    result <- switchv(c("horse", "fish", "cat", "bug"),
                      horse="fast",
                      cat="cute",
                      "what?")

    expect_equal(result, c("fast", "what?", "cute", "what?"))


    result <- switchv(c("horse", "fish", "cat", "bug"),
                      horse="fast",
                      cat="cute",
                      bug="ugly",
                      fish="wet")

    expect_equal(result, c("fast", "wet", "cute", "ugly"))

})
kbroman/broman documentation built on Feb. 11, 2024, 7:18 a.m.