tests/testthat/test_parse_date.R

context("test cs_parse_date function")

# load data ------------------------------------------------

## load january 2018 data
test_data <- january2018

# test inputs ------------------------------------------------

test_that("misspecified functions return errors", {
  expect_error(cs_parse_date(var = date_occur, dateVar = date, timeVar = time),
               "A existing data frame with data to be parsed must be specified for '.data'.")
  expect_error(cs_parse_date(test_data, dateVar = date, timeVar = time),
               "The column containing the data to be parsed must be specified for 'var'.")
  expect_error(cs_parse_date(test_data, var = date_occur, timeVar = time),
               "The name of the new column to be made containing the date must be specified for 'dateVar'.")
  expect_error(cs_parse_date(test_data, var = date_occur, dateVar = date),
               "The name of the new column to be made containing the time must be specified for 'timeVar'.")
})

# test function ------------------------------------------------

test_that("correctly specified functions execute without error", {
  expect_error(cs_parse_date(test_data, var = date_occur, dateVar = date, timeVar = time), NA)
  expect_error(cs_parse_date(test_data, var = "date_occur", dateVar = "date", timeVar = "time"), NA)
  expect_error(cs_parse_date(test_data, var = date_occur, dateVar = date, timeVar = time, keepDateTime = TRUE), NA)
})

Try the compstatr package in your browser

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

compstatr documentation built on July 8, 2020, 7:34 p.m.