tests/testthat/test_filter_count.R

context("test cs_filter_count function")

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

## load january 2018 data
test_data <- january2018

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

test_that("misspecified functions return errors", {
  expect_error(cs_filter_count(var = count),
               "A existing data frame with data to be edited must be specified for '.data'.")
  expect_error(cs_filter_count(test_data),
               "The column containing the data to be edited must be specified for 'var'.")
})

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

test_that("correctly specified functions execute without error", {
  expect_error(cs_filter_count(test_data, var = count), NA)
  expect_error(cs_filter_count(test_data, var = "count"), NA)
})

# test results ------------------------------------------------

results <- cs_filter_count(test_data, var = count)

test_that("results returned as expected", {
  expect_equal(nrow(results), 3762)
})
chris-prener/compStatR documentation built on Jan. 25, 2024, 10:03 p.m.