tests/testthat/test_codes.R

context("Varify Codes")

test_that("legitimate postcodes varify correctly", {
  expect_true(verify_post_code("M20 2LL"))
  expect_true(verify_post_code("BH20 6EE"))
})

test_that("multiple post codes are parsed correctly", {
  expect_equal(verify_post_code(c("M20 2LL", "AL5 3HE")), c(TRUE, TRUE))
})

test_that("incorrect postcodes are rejected correctly", {
  expect_false(verify_post_code("sdf 32f"))
  expect_false(verify_post_code("hippo"))
})

test_that("incorrect lengths are handled", {
  expect_error(verify_nhs(123))
})

test_that("incorrect data types are handled", {
  expect_error(verify_nhs(1234567890))
  expect_error(verify_nhs(c(1234567890, 0987654321)))
})

test_that("nhs numbers validate correctly", {
  expect_equal(verify_nhs("6744424270"), TRUE)
  expect_equal(verify_nhs(c("6744424270", "2925091350")), c(TRUE, TRUE))
  expect_equal(verify_nhs(c("6744424270", "0083041737", "2401060723")),
               c(TRUE, TRUE, TRUE))
  expect_equal(verify_nhs("1234567890"), FALSE)
  expect_equal(verify_nhs(c("6744424270", "1234567890")), c(TRUE, FALSE))
  expect_equal(verify_nhs(c("6744424270", "0083041737", "1234567890")),
               c(TRUE, TRUE, FALSE))
})
CC-HIC/icnarc2omop documentation built on March 4, 2020, 11:11 a.m.