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"))

})

Try the broman package in your browser

Any scripts or data that you put into this service are public.

broman documentation built on July 8, 2022, 5:07 p.m.