stRoke/tests/testthat/test-cpr_tools.R

42 lines
1.6 KiB
R
Raw Normal View History

2022-09-26 13:59:05 +02:00
testthat::test_that("cpr_check() works for vectors, giving logicals", {
2022-09-22 14:20:46 +02:00
result <- cpr_check(c("2310450637", "010115-4000", "0101896000","010189-3000","300450-1030","010150-4021"))
2022-09-26 13:59:05 +02:00
testthat::expect_equal(any(result), TRUE)
testthat::expect_type(result, "logical")
testthat::expect_equal(result[2], FALSE)
2022-09-22 14:20:46 +02:00
})
################################################################################
2022-09-26 13:59:05 +02:00
testthat::test_that("cpr_dob() works for vectors, giving logicals", {
2023-01-11 12:54:08 +01:00
cpr <- c("2310450637", "010115-4000", "0101896000",
"010189-3000","300450-1030",
"010219-7021","010150-4021")
testthat::expect_type(cpr_dob(cpr), "character")
testthat::expect_length(cpr_dob(cpr), 7)
})
testthat::test_that("cpr_dob() works for vectors,
giving expected warnings and NAs", {
cpr <- c("2310450637", "010115-4000", "0101896000",
"010189-3000","01018AAAL9","300450-1030",
"010219-7021","0039-7021","010150-4021")
result <- suppressWarnings(cpr_dob(cpr))
2023-01-05 10:21:46 +01:00
testthat::expect_type(result, "character")
2023-01-11 12:54:08 +01:00
testthat::expect_length(result, 9)
testthat::expect_true(any(is.na(result)))
testthat::expect_warning(cpr_dob(cpr))
2022-09-22 14:20:46 +02:00
})
2022-09-22 15:45:40 +02:00
################################################################################
2022-09-26 13:59:05 +02:00
testthat::test_that("cpr_female() works for vectors, giving logicals", {
2023-01-11 12:54:08 +01:00
result <- cpr_female(c("2310450637", "010115-4000", "0101896000",
"010189-3000","300450-1030","010150-4021"))
2022-09-26 13:59:05 +02:00
testthat::expect_type(result, "logical")
testthat::expect_length(result, 6)
testthat::expect_equal(result[2], TRUE)
2022-09-22 15:45:40 +02:00
})
2023-01-11 12:54:08 +01:00
################################################################################