tests/testthat/test-gini.R

context("gini")

#################
# gini testthat #
#################

test_that("gini throws error with invalid arguments", {
  
  # Unavailable geography
  expect_error(gini(geo = "zcta", state = "DC", year = 2020, quiet = TRUE))
  
  # Unavailable year
  expect_error(gini(state = "DC", year = 2005, quiet = TRUE))
  
  skip_if(Sys.getenv("CENSUS_API_KEY") == "")
  
  # Incorrect state
  expect_error(gini(state = "AB", year = 2020))
  
  # Unavailable geography for DC (only 1 'county' in DC so, alone, NDI cannot be computed)
  expect_error(gini(geo = "county", state = "DC", year = 2009, quiet = TRUE))
  
}
)   

test_that("gini works", {  
  
  skip_if(Sys.getenv("CENSUS_API_KEY") == "")
  
  expect_message(gini(state = "DC", year = 2020)) 
  
  expect_silent(gini(state = "DC", year = 2020, quiet = TRUE))
  
}
)  

Try the ndi package in your browser

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

ndi documentation built on May 29, 2024, 9:56 a.m.