AMR/tests/testthat/test-eucast.R

66 lines
2.4 KiB
R
Raw Normal View History

context("eucast.R")
2018-03-27 17:43:42 +02:00
test_that("EUCAST rules work", {
expect_error(EUCAST_rules(septic_patients, col_bactid = "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-07-23 14:14:03 +02:00
a <- data.frame(bactid =
c("KLEPNE", # Klebsiella pneumoniae
"PSEAER", # Pseudomonas aeruginosa
"ENTAER"), # Enterobacter aerogenes
2018-03-27 17:43:42 +02:00
amox = "-", # Amoxicillin
stringsAsFactors = FALSE)
2018-07-23 14:14:03 +02:00
b <- data.frame(bactid =
2018-07-26 16:30:42 +02:00
c("KLEPNE", # Klebsiella pneumoniae
"PSEAER", # Pseudomonas aeruginosa
"ENTAER"), # Enterobacter aerogenes
2018-03-27 17:43:42 +02:00
amox = "R", # Amoxicillin
stringsAsFactors = FALSE)
2018-07-30 00:57:49 +02:00
expect_warning(EUCAST_rules(a, info = FALSE))
expect_identical(suppressWarnings(EUCAST_rules(a, info = FALSE)), b)
2018-07-23 14:14:03 +02:00
expect_identical(suppressWarnings(interpretive_reading(a, info = TRUE)), b)
2018-04-02 16:05:09 +02:00
2018-07-23 14:14:03 +02:00
a <- data.frame(bactid =
c("STAAUR", # Staphylococcus aureus
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
2018-03-27 17:43:42 +02:00
coli = "-", # Colistin
stringsAsFactors = FALSE)
2018-07-23 14:14:03 +02:00
b <- data.frame(bactid =
2018-07-26 16:30:42 +02:00
c("STAAUR", # Staphylococcus aureus
"STCGRA"), # Streptococcus pyognenes (Lancefield Group A)
2018-03-27 17:43:42 +02:00
coli = "R", # Colistin
stringsAsFactors = FALSE)
2018-07-30 00:57:49 +02:00
expect_equal(suppressWarnings(EUCAST_rules(a, info = FALSE)), b)
# pita must be R in Enterobacteriaceae when tica is R
library(dplyr)
expect_equal(suppressWarnings(
septic_patients %>%
mutate(tica = as.rsi("R"),
pita = as.rsi("S")) %>%
EUCAST_rules(col_bactid = "bactid") %>%
left_join_microorganisms() %>%
filter(family == "Enterobacteriaceae") %>%
pull(pita) %>%
unique() %>%
as.character()),
"R")
# azit and clar must be equal to eryt
expect_equal(suppressWarnings(
septic_patients %>%
mutate(azit = as.rsi("R"),
clar = as.rsi("R")) %>%
EUCAST_rules(col_bactid = "bactid") %>%
pull(clar)),
suppressWarnings(
septic_patients %>%
EUCAST_rules(col_bactid = "bactid") %>%
left_join_microorganisms() %>%
pull(eryt)))
2018-03-27 17:43:42 +02:00
})