From 2ba05a834de061f99d1b47d331a379962c0fdbad Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 10:18:57 +0000 Subject: [PATCH 1/4] create initial autocode function unit tests --- R/icd_check.R | 67 ++++++++++++++++++++---------- tests/testthat/test-icd_autocode.R | 13 ++++++ 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/R/icd_check.R b/R/icd_check.R index b40c1eb..728c49c 100644 --- a/R/icd_check.R +++ b/R/icd_check.R @@ -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) ) } } @@ -64,16 +70,25 @@ 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" } } @@ -81,21 +96,31 @@ icd_check_language <- function(release = NULL, language, verbose = TRUE) { 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" } } diff --git a/tests/testthat/test-icd_autocode.R b/tests/testthat/test-icd_autocode.R index 21e19fd..983be6f 100644 --- a/tests/testthat/test-icd_autocode.R +++ b/tests/testthat/test-icd_autocode.R @@ -1,2 +1,15 @@ # Test autocode function ------------------------------------------------------- +testthat::expect_s3_class( + icd_autocode_foundation("colorectal cancer"), + "tbl_df" +) + +testthat::expect_message( + icd_autocode_foundation("colorectal cancer") +) + +testthat::expect_error( + icd_autocode_foundation("colorectal cancer", release = "2025-01") +) + From fb581726ced3dbedaf7c73f8f10860a8590dd5dc Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 11:24:12 +0000 Subject: [PATCH 2/4] add more autocode tests --- tests/testthat/test-icd_autocode.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-icd_autocode.R b/tests/testthat/test-icd_autocode.R index 983be6f..9645d97 100644 --- a/tests/testthat/test-icd_autocode.R +++ b/tests/testthat/test-icd_autocode.R @@ -9,7 +9,16 @@ 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" +) From a6298fe7a0a91186965a5775cce192e428ce9524 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 11:34:19 +0000 Subject: [PATCH 3/4] add more autocode tests --- tests/testthat/test-icd_autocode.R | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/testthat/test-icd_autocode.R b/tests/testthat/test-icd_autocode.R index 9645d97..029164d 100644 --- a/tests/testthat/test-icd_autocode.R +++ b/tests/testthat/test-icd_autocode.R @@ -1,5 +1,7 @@ # Test autocode function ------------------------------------------------------- +## Autocode foundation ---- + testthat::expect_s3_class( icd_autocode_foundation("colorectal cancer"), "tbl_df" @@ -9,6 +11,10 @@ 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) ) @@ -22,3 +28,32 @@ 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" +) From f4719c5f85dc942ac818a19973712758bb256283 Mon Sep 17 00:00:00 2001 From: Ernest Guevarra Date: Wed, 20 Mar 2024 12:35:48 +0000 Subject: [PATCH 4/4] add more autocode tests --- tests/testthat/test-icd_autocode.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testthat/test-icd_autocode.R b/tests/testthat/test-icd_autocode.R index 029164d..5293c80 100644 --- a/tests/testthat/test-icd_autocode.R +++ b/tests/testthat/test-icd_autocode.R @@ -7,6 +7,11 @@ testthat::expect_s3_class( "tbl_df" ) +testthat::expect_s3_class( + icd_autocode_foundation("colorectal cancer", release = "2024-01"), + "tbl_df" +) + testthat::expect_message( icd_autocode_foundation("colorectal cancer") )