tests/testthat/test-data-validity.R

db <- list(
  caracteristique = caracteristique,
  lieu = lieu,
  usager = usager,
  vehicule = vehicule,
  vehicule_immatricule = vehicule_immatricule
)

test_that("Test nrow carac and lieu", {
  expect_true(
    nrow(db$carac) == nrow(db$lieu)
    )
})

test_that("Test min year", {
  expect_true(
    min(db$carac$an, na.rm = TRUE) == 2005
    )
})

test_that("Test max year", {
  expect_true(
    max(db$carac$an, na.rm = TRUE) == 2021
    )
})

test_that("Test months", {
  expect_true(
    all(unique(db$carac$mois) %in% 1:12)
    )
})

test_that("Test days", {
  expect_true(
    all(unique(db$carac$jour) %in% 1:31)
    )
})

# test_that("Test hours", {
#   x <- range(as.difftime(db$carac$hrmn, "%H:%M", units = "secs"))
#   y <- as.difftime(c("0:01", "23:59"), format = "%H:%M", units = "secs")
#   expect_true(all(x == y))
# })

test_that("Test birth year", {
  expect_true(all(range(db$usager$an_nais, na.rm = TRUE) == c(1896, 2021)))
})
ngsanogo/corpoaccident documentation built on Oct. 20, 2023, 2:27 a.m.