AMR/tests/testthat/test-rsi.R

54 lines
2.4 KiB
R
Raw Normal View History

# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# AUTHORS #
# Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# LICENCE #
# This package is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License version 2.0, #
# as published by the Free Software Foundation. #
# #
# This R package is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License version 2.0 for more details. #
# ==================================================================== #
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(septic_patients, is.rsi.eligible)),
rep(FALSE, length(septic_patients)))
library(dplyr)
# 40 rsi columns
2018-11-02 15:04:48 +01:00
expect_equal(septic_patients %>%
mutate_at(vars(peni:rifa), as.character) %>%
lapply(is.rsi.eligible) %>%
as.logical() %>%
sum(),
40)
2018-11-02 14:55:29 +01:00
})