stRoke/tests/testthat/test-cpr_tools.R

100 lines
2.7 KiB
R
Raw Normal View History

2022-09-26 13:59:05 +02:00
testthat::test_that("cpr_check() works for vectors, giving logicals", {
2023-01-12 13:44:29 +01: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-12 13:44:29 +01:00
cpr <- c(
"2310450637",
"010115-4000",
"0101896000",
"010189-3000",
"300450-1030",
"010219-7021",
"010150-4021"
)
2023-01-11 12:54:08 +01:00
testthat::expect_type(cpr_dob(cpr), "character")
testthat::expect_length(cpr_dob(cpr), 7)
})
2023-01-12 13:44:29 +01:00
testthat::test_that("cpr_dob() works for vectors,
2023-01-11 12:54:08 +01:00
giving expected warnings and NAs", {
2023-01-12 13:44:29 +01:00
cpr <- c(
"2310450637",
"010115-4000",
"0101896000",
"010189-3000",
"01018AAAL9",
"300450-1030",
"010219-7021",
"0039-7021",
"010150-4021"
)
result <- suppressWarnings(cpr_dob(cpr))
testthat::expect_type(result, "character")
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-12 13:44:29 +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-12 13:44:29 +01:00
testthat::test_that("cpr_female() works for vectors, giving logicals", {
result <- cpr_female(
c(
"2310450637",
"010115-4000",
"0101896000",
"010189-3000",
"300450-1030",
"010150-4021"
)
)
testthat::expect_type(result, "logical")
testthat::expect_length(result, 6)
testthat::expect_equal(result[2], TRUE)
testthat::expect_error(cpr_female(matrix(
c(
"2310450637",
"010115-4000",
"0101896000",
"010189-3000",
"300450-1030",
"010150-4021"
),
ncol = 3
)))
})
2023-01-11 12:54:08 +01:00
2023-01-12 13:44:29 +01:00
################################################################################