tests/testthat/test-convert.R

library(testthat)
library(usa)

x <- c("ID", "new mexico", 2)
test_that("conversion to abbreviation", {
  y <- usa::state_convert(x, "abb")
  expect_equal(y, c("ID", "NM", "AK"))
})

test_that("conversion to abbreviation", {
  y <- usa::state_convert(x, "fips")
  expect_equal(y, c("16", "35", "02"))
})

test_that("conversion to full name", {
  y <- usa::state_convert(x, "names")
  expect_equal(y, c("Idaho", "New Mexico", "Alaska"))
})

Try the usa package in your browser

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

usa documentation built on May 29, 2024, 12:09 p.m.