tests/fars_tests.R

## fars package specific tests
## R W Palin 2019-10-16

# library(testthat)
# library(fars)

testthat::test_that("fars_read: invalid filename gives an error",
   testthat::expect_error(
      fars::fars_read("BAD_FILE")
   )
)

testthat::test_that("make_filename: year resolves to correct filename",
   testthat::expect_equal(
      fars::make_filename(2013, internal=FALSE), "accident_2013.csv.bz2"
   )
)

testthat::test_that("make_filename: invalid sample data raises a message",
   testthat::expect_message(
      fars::make_filename(2012)
   )
)

testthat::test_that("fars_read_years: check length of output matches number of years sample data",
   testthat::expect_equal(
      length(fars::fars_read_years(2013:2015)), 3
   )
)

testthat::test_that("fars_summarize_years: check total of numbers in sample data summary",
   testthat::expect_equal(
      sum(fars::fars_summarize_years(2013:2015)), 92502
   )
)

testthat::test_that("fars_map_state: valid call does not write to the console",
   testthat::expect_silent(
      fars::fars_map_state(42,2013)
   )
)

testthat::test_that("fars_map_state: invalid data raises an error",
   testthat::expect_error(
      fars::fars_map_state(2,2013)
   )
)
rwpalin/fars documentation built on Nov. 5, 2019, 5:10 a.m.