1
0
mirror of https://github.com/msberends/AMR.git synced 2025-01-14 14:41:38 +01:00

unit tests

This commit is contained in:
dr. M.S. (Matthijs) Berends 2023-06-22 14:16:25 +02:00
parent 3083828e15
commit c8bda784a6
3 changed files with 8 additions and 6 deletions

4
R/mo.R
View File

@ -267,6 +267,8 @@ as.mo <- function(x,
x_out <- trimws2(gsub(" +", " ", x_out, perl = TRUE))
x_search_cleaned <- x_out
x_out <- tolower(x_out)
# when x_search_cleaned are only capitals (such as in codes), make them lowercase to increase matching score
x_search_cleaned[x_search_cleaned == toupper(x_search_cleaned)] <- x_out[x_search_cleaned == toupper(x_search_cleaned)]
# first check if cleaning led to an exact result, case-insensitive
if (x_out %in% AMR_env$MO_lookup$fullname_lower) {
@ -334,7 +336,7 @@ as.mo <- function(x,
# correct back for kingdom
minimum_matching_score_current <- minimum_matching_score_current / AMR_env$MO_lookup$kingdom_index[match(mo_to_search, AMR_env$MO_lookup$fullname)]
minimum_matching_score_current <- pmax(minimum_matching_score_current, m)
if (all(m <= 0.55, na.rm = TRUE)) {
if (length(m) > 1 && all(m <= 0.55, na.rm = TRUE)) {
# if the highest score is 0.5, we have nothing serious - 0.5 is the lowest for pathogenic group 1
# make everything NA so the results will get removed below
m[seq_len(length(m))] <- NA_real_

View File

@ -47,10 +47,10 @@ expect_false(any(is.na(microorganisms.codes$mo)))
expect_true(all(dosage$ab %in% antibiotics$ab))
expect_true(all(dosage$name %in% antibiotics$name))
# check valid disks/MICs
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_S", drop = TRUE]))))
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC"), "breakpoint_R", drop = TRUE]))))
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_S", drop = TRUE]))))
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK"), "breakpoint_R", drop = TRUE]))))
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_S", drop = TRUE]))))
expect_false(any(is.na(as.mic(clinical_breakpoints[which(clinical_breakpoints$method == "MIC" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_R", drop = TRUE]))))
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_S", drop = TRUE]))))
expect_false(any(is.na(as.disk(clinical_breakpoints[which(clinical_breakpoints$method == "DISK" & clinical_breakpoints$ref_tbl != "ECOFF"), "breakpoint_R", drop = TRUE]))))
# antibiotic names must always be coercible to their original AB code
expect_identical(as.ab(antibiotics$name), antibiotics$ab)

View File

@ -28,7 +28,7 @@
# ==================================================================== #
MOs <- subset(microorganisms, !is.na(mo) & nchar(mo) > 3)
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo)))
expect_identical(as.character(MOs$mo), as.character(as.mo(MOs$mo, keep_synonyms = TRUE)))
expect_identical(
as.character(as.mo(c("E. coli", "H. influenzae"), keep_synonyms = FALSE)),