tests/testthat/test-clean_numeric.R

context("clean_numeric")

test_that("clean_numeric works as expected", {

  data(ll1)
  data(ll2)
  data(clean_num1)

  # test basic
  x1 <- clean_numeric(ll1, vars = c("age", "contacts"), dict = clean_num1)
  expect_equal(dim(x1), dim(ll1))
  expect_equal(names(x1), names(ll1))
  expect_is(x1$age, "numeric")
  expect_is(x1$contacts, "numeric")

  # test arg fn
  x2 <- clean_numeric(ll1, vars = c("age", "contacts"), dict = clean_num1, fn = as.integer)
  expect_is(x2$age, "integer")
  expect_is(x2$contacts, "integer")

  # test with no dictionary-based cleaning
  x3 <- clean_numeric(ll1, vars = c("age", "contacts"))
  expect_is(x3$age, "numeric")
  expect_is(x3$contacts, "numeric")
})
epicentre-msf/dbc documentation built on Oct. 24, 2023, 9:25 p.m.