Skip to content

Commit

Permalink
add unit tests for missing_value in messy_linelist
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlambert committed Feb 20, 2025
1 parent c7c3151 commit d03ea10
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/testthat/test-messy_linelist.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ test_that("messy_linelist works as expected by default", {
expect_gt(anyDuplicated(messy_ll), 0)
})

test_that("messy_linelist works with different missing_value", {
messy_ll <- suppressWarnings(
messy_linelist(
ll,
prop_missing = 0.8,
missing_value = -99L,
numeric_as_char = FALSE,
prop_int_as_word = 0
)
)
expect_type(messy_ll$id, "integer")
expect_type(messy_ll$age, "integer")
expect_type(messy_ll$date_onset, "character")
expect_type(messy_ll$case_name, "character")
})

test_that("messy_linelist works with higher proportion of spelling mistakes", {
messy_ll <- messy_linelist(
ll,
Expand Down Expand Up @@ -131,6 +147,18 @@ test_that("messy_linelist works with inconsistent_id", {
expect_false(identical(ll$id, messy_ll$id))
})

test_that("messy_linelist warns when coercing from missing_value", {
expect_warning(
messy_linelist(
ll,
missing_value = "n/a",
numeric_as_char = FALSE,
date_as_char = FALSE
),
regexp = "(The linelist columns)*(date_)*(are being coerced to character)"
)
})

test_that("messy_linelist errors with incorrect linelist", {
expect_error(
messy_linelist(data.frame(a = 1)),
Expand Down

0 comments on commit d03ea10

Please sign in to comment.