AMR/tests/testthat/test-eucast.R

78 lines
2.7 KiB
R
Raw Normal View History

context("eucast.R")
2018-03-27 17:43:42 +02:00
test_that("EUCAST rules work", {
2018-11-01 20:23:33 +01:00
expect_error(suppressWarnings(EUCAST_rules(septic_patients, col_mo = "Non-existing")))
2018-07-23 14:14:03 +02:00
expect_identical(colnames(septic_patients),
colnames(suppressWarnings(EUCAST_rules(septic_patients))))
2018-05-02 14:56:25 +02:00
2018-10-17 17:32:34 +02:00
a <- data.frame(mo = c("KLEPNE", # Klebsiella pneumoniae
"PSEAER", # Pseudomonas aeruginosa
"ENTAER"), # Enterobacter aerogenes
2018-03-27 17:43:42 +02:00
amox = "-", # Amoxicillin
stringsAsFactors = FALSE)
2018-10-17 17:32:34 +02:00
b <- data.frame(mo = c("KLEPNE", # Klebsiella pneumoniae
"PSEAER", # Pseudomonas aeruginosa
"ENTAER"), # Enterobacter aerogenes
amox = "R", # Amoxicillin
2018-03-27 17:43:42 +02:00
stringsAsFactors = FALSE)
2018-11-01 20:23:33 +01:00
expect_identical(suppressWarnings(EUCAST_rules(a, "mo", info = FALSE)), b)
expect_identical(suppressWarnings(interpretive_reading(a, "mo", info = TRUE)), b)
2018-04-02 16:05:09 +02:00
2018-10-17 17:32:34 +02:00
a <- data.frame(mo = c("STAAUR", # Staphylococcus aureus
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
coli = "-", # Colistin
2018-03-27 17:43:42 +02:00
stringsAsFactors = FALSE)
2018-10-17 17:32:34 +02:00
b <- data.frame(mo = c("STAAUR", # Staphylococcus aureus
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
coli = "R", # Colistin
2018-03-27 17:43:42 +02:00
stringsAsFactors = FALSE)
2018-11-01 20:23:33 +01:00
expect_equal(suppressWarnings(EUCAST_rules(a, "mo", info = FALSE)), b)
2018-11-01 20:23:33 +01:00
# piperacillin must be R in Enterobacteriaceae when tica is R
library(dplyr)
expect_equal(suppressWarnings(
septic_patients %>%
mutate(tica = as.rsi("R"),
2018-11-01 20:23:33 +01:00
pipe = as.rsi("S")) %>%
2018-08-31 13:36:19 +02:00
EUCAST_rules(col_mo = "mo") %>%
left_join_microorganisms() %>%
filter(family == "Enterobacteriaceae") %>%
2018-11-01 20:23:33 +01:00
pull(pipe) %>%
unique() %>%
as.character()),
"R")
2018-10-17 17:32:34 +02:00
# azit and clar must be equal to eryt
2018-10-17 17:32:34 +02:00
a <- suppressWarnings(
septic_patients %>%
transmute(mo,
eryt,
azit = as.rsi("R"),
clar = as.rsi("R")) %>%
EUCAST_rules(col_mo = "mo") %>%
pull(clar))
b <- suppressWarnings(
septic_patients %>%
2018-10-17 17:32:34 +02:00
select(mo, eryt) %>%
2018-08-31 13:36:19 +02:00
EUCAST_rules(col_mo = "mo") %>%
2018-10-17 17:32:34 +02:00
pull(eryt))
expect_identical(a[!is.na(b)],
b[!is.na(b)])
# amox is inferred by benzylpenicillin in Kingella kingae
expect_equal(
as.list(EUCAST_rules(
data.frame(mo = as.mo("Kingella kingae"),
peni = "S",
amox = "-",
stringsAsFactors = FALSE)
, info = FALSE))$amox,
"S")
2018-10-19 00:17:03 +02:00
expect_output(suppressWarnings(EUCAST_rules(septic_patients, verbose = TRUE)))
2018-03-27 17:43:42 +02:00
})