Skip to content

Commit

Permalink
Merge pull request #87 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
add tests for new functions
  • Loading branch information
ernestguevarra authored Jun 29, 2024
2 parents a7575fa + bdba1fa commit 61450f0
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/cod_check_dod.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ cod_check_dod <- function(dod) {
dod_check <- ifelse(is.na(dod), 1L, 0L)

dod_check <- ifelse(
stringr::str_detect(string = dod, pattern = "[0-9]{4}", negate = TRUE),
nchar(dod) > 4 | stringr::str_detect(dod, pattern = "[a-zA-Z]"),
1L, 0L
)

Expand Down
2 changes: 1 addition & 1 deletion R/cod_check_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cod_check_codedit_input <- function(df) {
## Return tibble of check results ----
tibble::tibble(
sex_check, age_check,
code_check = tibble::tibble(code_check, code_check_note),
code_check, code_check_note,
dod_check
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/cod_structure_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' record identifiers. Default to NULL. If NULL, unique record identifiers
#' will be generated.
#'
#' @returns A data.frame with 6 columns and number of rows equal to `df` with
#' @returns A tibble with 6 columns and number of rows equal to `df` with
#' names `"FreeId"`, `"Sex"`, `"Age Value"`, `"Age Type"`, `"Code"`, and
#' `"Death Date"`.
#'
Expand Down
2 changes: 1 addition & 1 deletion man/cod_structure.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-cod_check_dod.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Tets for cod_check_dod -------------------------------------------------------

testthat::test_that(
"cod_check_dod outputs appropriate results", {
expect_s3_class(cod_check_dod("2024"), "tbl")

expect_identical(
cod_check_dod("2024"),
tibble::tibble(
dod_check = 0L,
dod_check_note = "No issues with date of death value"
)
)

expect_identical(
cod_check_dod("2024-06-01"),
tibble::tibble(
dod_check = 1L,
dod_check_note = "Date of death value is not in year format"
)
)
})
18 changes: 18 additions & 0 deletions tests/testthat/test-cod_check_input.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tests for cod_check_input ----------------------------------------------------

testthat::test_that(
"cod_check_input outputs appropriate results", {
expect_s3_class(cod_check_codedit_input(icd10_example), "tbl")

expect_named(
cod_check_codedit_input(icd10_example),
c("sex_check", "sex_check_note",
"age_check", "age_check_note",
"code_check", "code_check_note",
"dod_check", "dod_check_note")
)

expect_warning(
cod_check_codedit_input(icd10_example |> dplyr::select(-FreeId))
)
})
27 changes: 27 additions & 0 deletions tests/testthat/test-cod_structure_input.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Tests for cod_structure_input ------------------------------------------------

df <- data.frame(
id = 1:3,
sex = c(1, 1, 2),
dob = c("1977-11-05", "1971-04-04", "2012-08-13"),
dod = c("2024-06-28", "2023-10-11", "2023-09-25"),
code = c("P219", "O230", "Q913")
)


testthat::test_that(
"cod_structure_input outputs appropriate results", {
expect_s3_class(
cod_structure_input(
df, sex = "sex", dob = "dob", dod = "dod", code = "code"
),
"tbl"
)

expect_s3_class(
cod_structure_input(
df = df, sex = "sex", dob = "dob", dod = "dod", code = "code", id = "id"
),
"tbl"
)
})

0 comments on commit 61450f0

Please sign in to comment.