diff --git a/tests/testthat/test-sir.R b/tests/testthat/test-sir.R index aaeaee375..f2176af0f 100644 --- a/tests/testthat/test-sir.R +++ b/tests/testthat/test-sir.R @@ -532,30 +532,32 @@ test_that("test-sir.R", { # issue #239 — custom reference_data support test_that("custom reference_data: non-EUCAST/CLSI guideline produces R", { - # use any MIC/human row as structural template, then override mo/ab/guideline/breakpoints + # Take the first MIC/human row (B_ACHRMB_XYLS / MEM) as a template. + # Only override guideline and breakpoints; keep mo/ab as / class objects. my_bp <- clinical_breakpoints[clinical_breakpoints$method == "MIC" & clinical_breakpoints$type == "human", ][1, ] my_bp$guideline <- "MyLab 2025" - my_bp$mo <- "B_ESCHR_COLI" - my_bp$ab <- "AMC" my_bp$breakpoint_S <- 8 my_bp$breakpoint_R <- 32 - # guideline omitted: all rows in reference_data are used + mo_val <- as.character(my_bp$mo) # "B_ACHRMB_XYLS" + ab_val <- as.character(my_bp$ab) # "MEM" + + # guideline omitted: all rows in reference_data are used; R via open interval (>) expect_equal(as.character(suppressMessages( - as.sir(as.mic(64), mo = "E. coli", ab = "AMC", reference_data = my_bp) + as.sir(as.mic(64), mo = mo_val, ab = ab_val, reference_data = my_bp) )), "R") expect_equal(as.character(suppressMessages( - as.sir(as.mic(16), mo = "E. coli", ab = "AMC", reference_data = my_bp) + as.sir(as.mic(16), mo = mo_val, ab = ab_val, reference_data = my_bp) )), "I") # at R breakpoint value must be I (open interval: > not >=) expect_equal(as.character(suppressMessages( - as.sir(as.mic(32), mo = "E. coli", ab = "AMC", reference_data = my_bp) + as.sir(as.mic(32), mo = mo_val, ab = ab_val, reference_data = my_bp) )), "I") # guideline explicitly set: same result when it matches the data expect_equal(as.character(suppressMessages( - as.sir(as.mic(64), mo = "E. coli", ab = "AMC", + as.sir(as.mic(64), mo = mo_val, ab = ab_val, guideline = "MyLab 2025", reference_data = my_bp) )), "R") }) @@ -564,16 +566,18 @@ test_that("custom reference_data: host = NA acts as host-agnostic fallback", { my_bp <- clinical_breakpoints[clinical_breakpoints$method == "MIC" & clinical_breakpoints$type == "human", ][1, ] my_bp$guideline <- "MyLab 2025" - my_bp$mo <- "B_ESCHR_COLI" - my_bp$ab <- "AMC" my_bp$type <- "animal" - my_bp$host <- NA + my_bp$host <- NA_character_ # must stay character class, not logical NA my_bp$breakpoint_S <- 8 my_bp$breakpoint_R <- 32 + mo_val <- as.character(my_bp$mo) + ab_val <- as.character(my_bp$ab) + # NA host should match when no species-specific row exists; guideline omitted result <- suppressMessages( - as.sir(as.mic(64), mo = "E. coli", ab = "AMC", host = "dogs", reference_data = my_bp) + as.sir(as.mic(64), mo = mo_val, ab = ab_val, + host = "dogs", breakpoint_type = "animal", reference_data = my_bp) ) expect_equal(as.character(result), "R") })