mirror of
https://github.com/msberends/AMR.git
synced 2026-05-31 12:21:40 +02:00
Fix unit tests for custom reference_data (#239)
- Do not override my_bp$mo / my_bp$ab in tests: assigning plain character strips the <mo>/<ab> class, which check_reference_data() rejects. Use the mo/ab values already present in the source row instead. - Use NA_character_ instead of NA for my_bp$host so the host column keeps its character class. - Pass breakpoint_type = "animal" explicitly in the host-fallback test since the custom reference_data only contains animal-type breakpoints. https://claude.ai/code/session_01Q8KtFFGG9qrjAgLJBbxG2U
This commit is contained in:
@@ -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 <mo>/<ab> 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")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user