tests/testthat/test-pad_chi.R

#check outputs
test_that("padding works on 9 characters", {
  expect_equal(pad_chi("123456789"), "0123456789")
  expect_equal(nchar(pad_chi("123456789")), 10)
})

test_that("length of less than 9 not padded", {
  expect_equal(pad_chi("12345678"), "12345678")
  expect_equal(nchar(pad_chi("12345678")), 8)
})

test_that("length of 10 is not padded", {
  expect_equal(pad_chi("1234567890"), "1234567890")
  expect_equal(nchar(pad_chi("1234567890")), 10)
})

test_that("length of > 10 is not padded", {
  expect_equal(pad_chi("01234567890"), "01234567890")
  expect_equal(nchar(pad_chi("01234567890")), 11)
})

#check number class is invalid
test_that("numeric input fails", {
  expect_error(pad_chi(123),
               "input should be character class - try adding col_types = 'c' to read_csv")
})
graemegowans/chilir documentation built on March 30, 2020, 10:14 p.m.