tests/testthat/test-normal-city.R

library(testthat)
library(campfin)

expect_detect <- function(object, pattern, negate = FALSE) {
  expect_true(all(str_detect(object, pattern, negate = negate)))
}

test_that("normal city can convert and remove invalid", {
  x <- c("Washington", "Unknown", "XXXXXX", "DC", "Washington, DC")
  y <- normal_city(x, abbs = c(DC = "Washington"), states = "DC", na = invalid_city, na_rep = TRUE)
  expect_type(y, "character")
  expect_detect(na.omit(y), "\\d", negate = TRUE)
  expect_detect(na.omit(y), "DC", negate = TRUE)
  expect_detect(na.omit(y), "[:lower:]", negate = TRUE)
  expect_equal(count_na(y), 2)
})

Try the campfin package in your browser

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

campfin documentation built on Oct. 20, 2023, 5:06 p.m.