tests/testthat/test-getCountryCode.R

# -----------------------------------------------------------------------------
testthat::context("getCountryCode()")

testthat::test_that("handles errors correctly", {
  testthat::expect_error(getCountryCode())
  testthat::expect_error(getCountryCode(0,100))
})

testthat::test_that("returns correct name", {
  testthat::expect_match(getCountryCode(2, 47), "FR")
  testthat::expect_match(getCountryCode(-80, 40), "US")
  testthat::expect_match(getCountryCode(c(120,-17), c(-1.5,15)), "ID|SN")
  testthat::expect_match(getCountryCode(c(-87.1, 73.6, 26.2, -123), c(5.5, -52.9, 35.8, 48.7)),
                         "CR|AU|GR|US")
})

testthat::test_that("subsetting with countryCodes works", {
  testthat::expect_match(getCountryCode(2, 47), "FR")
  testthat::expect_match(getCountryCode(2, 47, countryCodes = c("FR")), "FR")
  testthat::expect_match(getCountryCode(2, 47, countryCodes = "FR"), "FR")
})

testthat::test_that("allData returns are correct dimension and type", {
  testthat::expect_s3_class(getCountryCode(2, 47, allData = TRUE), "data.frame")
  testthat::expect_equal(dim(getCountryCode(2, 47, allData = TRUE)), c(1,3))
  testthat::expect_s3_class(getCountryCode(c(120,-17), c(-1.5,15), allData = TRUE), "data.frame")
  testthat::expect_equal(dim(getCountryCode(c(120,-17), c(-1.5,15), allData = TRUE)), c(2,3))
})

Try the MazamaSpatialUtils package in your browser

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

MazamaSpatialUtils documentation built on Nov. 3, 2024, 9:07 a.m.