AMR/tests/testthat/test-rsi.R

107 lines
3.9 KiB
R
Raw Normal View History

# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
2019-01-02 23:24:07 +01:00
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
2019-01-02 23:24:07 +01:00
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
2019-01-02 23:24:07 +01:00
# This R package is free software; you can freely use and distribute #
# it for both personal and commercial purposes under the terms of the #
# GNU General Public License version 2.0 (GNU GPL-2), as published by #
# the Free Software Foundation. #
# #
# This R package was created for academic research and was publicly #
# released in the hope that it will be useful, but it comes WITHOUT #
# ANY WARRANTY OR LIABILITY. #
2019-04-05 18:47:39 +02:00
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
context("rsi.R")
test_that("rsi works", {
expect_true(as.rsi("S") < as.rsi("I"))
expect_true(as.rsi("I") < as.rsi("R"))
expect_true(as.rsi("R") > as.rsi("S"))
expect_true(is.rsi(as.rsi("S")))
# print plots, should not raise errors
barplot(as.rsi(c("S", "I", "R")))
plot(as.rsi(c("S", "I", "R")))
print(as.rsi(c("S", "I", "R")))
expect_equal(suppressWarnings(as.logical(as.rsi("INVALID VALUE"))), NA)
2018-12-07 12:04:55 +01:00
expect_equal(summary(as.rsi(c("S", "R"))), c("Class" = "rsi",
"<NA>" = "0",
"Sum S" = "1",
"Sum IR" = "1",
"-Sum R" = "1",
"-Sum I" = "0"))
2018-11-02 14:55:29 +01:00
expect_identical(as.logical(lapply(example_isolates, is.rsi.eligible)),
rep(FALSE, length(example_isolates)))
2018-11-02 14:55:29 +01:00
library(dplyr)
# 40 rsi columns
expect_equal(example_isolates %>%
2019-05-10 16:44:59 +02:00
mutate_at(vars(PEN:RIF), as.character) %>%
2018-11-02 15:04:48 +01:00
lapply(is.rsi.eligible) %>%
as.logical() %>%
sum(),
40)
2018-11-02 14:55:29 +01:00
})
2019-05-13 10:10:16 +02:00
test_that("mic2rsi works", {
expect_equal(as.character(
as.rsi(x = as.mic(0.125),
mo = "B_STRPT_PNE",
ab = "AMX",
guideline = "EUCAST")),
"S")
expect_equal(as.character(
as.rsi(x = as.mic(4),
mo = "B_STRPT_PNE",
ab = "AMX",
guideline = "EUCAST")),
"R")
expect_true(example_isolates %>%
2019-05-13 10:10:16 +02:00
mutate(amox_mic = as.mic(2)) %>%
select(mo, amox_mic) %>%
as.rsi() %>%
pull(amox_mic) %>%
is.rsi())
})
test_that("disk2rsi works", {
expect_equal(as.character(
as.rsi(x = as.disk(22),
mo = "B_STRPT_PNE",
ab = "ERY",
guideline = "CLSI")),
"S")
expect_equal(as.character(
as.rsi(x = as.disk(18),
mo = "B_STRPT_PNE",
ab = "ERY",
guideline = "CLSI")),
"I")
expect_equal(as.character(
as.rsi(x = as.disk(10),
mo = "B_STRPT_PNE",
ab = "ERY",
guideline = "CLSI")),
"R")
expect_true(example_isolates %>%
2019-05-13 10:10:16 +02:00
mutate(amox_disk = as.disk(15)) %>%
select(mo, amox_disk) %>%
as.rsi(guideline = "CLSI") %>%
pull(amox_disk) %>%
is.rsi())
})