Skip to content

Commit

Permalink
Merge pull request #76 from OxfordIHTM/dev
Browse files Browse the repository at this point in the history
create initial autocode function unit tests
  • Loading branch information
ernestguevarra authored Mar 20, 2024
2 parents 79d0bf7 + f4719c5 commit 100def8
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 21 deletions.
67 changes: 46 additions & 21 deletions R/icd_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,22 @@ icd_check_release <- function(release, verbose = TRUE) {
Classification[`Release ID` == release]
)

if (verbose) message(
paste0(
"Release `", release, "` matches a known release for ",
icd_set, "."
if (verbose)
message(
paste0(
"Release `", release, "` matches a known release for ",
icd_set, "."
) |>
strwrap(width = 80)
)
)
} else {
stop(
"Release `", release, "` does not match any known release for ICD-11
or ICD-10. Please verify and check with `icd_versions` and try again."
paste0(
"Release `", release,
"` does not match any known release for ICD-11 or ICD-10.",
" Please verify and check with `icd_versions` and try again."
) |>
strwrap(width = 80)
)
}
}
Expand All @@ -64,38 +70,57 @@ icd_check_language <- function(release = NULL, language, verbose = TRUE) {

if (length(language) == 1) {
if (language %in% languages_available) {
if (verbose) message(
paste0("Language `", language, "` is available for the release specified.")
)
if (verbose)
message(
paste0(
"Language `", language,
"` is available for the release specified."
) |>
strwrap(width = 80)
)
} else {
warning(
paste0(
"Language `", language,
"` is not available for the release specified. Returning results for `en` (default)."
)
"` is not available for the release specified. Returning results for
`en` (default)."
) |>
strwrap(width = 80)
)

## Set language to default ----
language <- "en"
}
}

if (length(language) > 1) {
if (any(language %in% languages_available)) {

## Detect languages ----
language_result <- language[language %in% languages_available]

message(
paste0(
"The following languages requested are available for the release specified: ",
language_result, "."
)
)

## Set language to language_result ----
language <- language_result

## Show message? ----
if (verbose)
message(
paste0(
"The following languages requested are available for the release
specified: ", language_result, "."
) |>
strwrap(width = 80)
)
} else {
warning(
paste0(
"None of the languages requested are available for the release specified. Returning results for `en` (default).")
strwrap(
"None of the languages requested are available for the release
specified. Returning results for `en` (default).",
width = 80
)
)

## Set language to default ----
language <- "en"
}
}
Expand Down
62 changes: 62 additions & 0 deletions tests/testthat/test-icd_autocode.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# Test autocode function -------------------------------------------------------

## Autocode foundation ----

testthat::expect_s3_class(
icd_autocode_foundation("colorectal cancer"),
"tbl_df"
)

testthat::expect_s3_class(
icd_autocode_foundation("colorectal cancer", release = "2024-01"),
"tbl_df"
)

testthat::expect_message(
icd_autocode_foundation("colorectal cancer")
)

testthat::expect_error(
icd_autocode_foundation("colorectal cancer", release = "2025-01")
)

testthat::expect_no_message(
icd_autocode_foundation("colorectal cancer", verbose = FALSE)
)

testthat::expect_type(
icd_autocode_foundation("colorectal cancer", tabular = FALSE),
"list"
)

testthat::expect_s3_class(
icd_autocode_foundation("colorectal cancer", threshold = 1),
"tbl_df"
)

## Autocode linearisation - mms ----

testthat::expect_s3_class(
icd_autocode_mms("colorectal cancer"),
"tbl_df"
)

testthat::expect_message(
icd_autocode_mms("colorectal cancer")
)

testthat::expect_error(
icd_autocode_mms("colorectal cancer", release = "2025-01")
)

testthat::expect_no_message(
icd_autocode_mms("colorectal cancer", verbose = FALSE)
)

testthat::expect_type(
icd_autocode_mms("colorectal cancer", tabular = FALSE),
"list"
)

testthat::expect_s3_class(
icd_autocode_mms("colorectal cancer", threshold = 1),
"tbl_df"
)

0 comments on commit 100def8

Please sign in to comment.