1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 16:42:10 +02:00
This commit is contained in:
2019-05-13 10:10:16 +02:00
parent 0444c4ed9d
commit 38a4421450
36 changed files with 475 additions and 213 deletions

View File

@ -36,6 +36,9 @@ test_that("as.ab works", {
expect_identical(class(as.ab("amox")), "ab")
expect_identical(class(pull(antibiotics, ab)), "ab")
expect_true(is.ab(as.ab("amox")))
expect_output(print(as.ab("amox")))
expect_output(print(data.frame(a = as.ab("amox"))))
expect_warning(as.ab("Z00ZZ00")) # not yet available in data set
expect_warning(as.ab("UNKNOWN"))

39
tests/testthat/test-atc.R Executable file
View File

@ -0,0 +1,39 @@
# ==================================================================== #
# TITLE #
# Antimicrobial Resistance (AMR) Analysis #
# #
# SOURCE #
# https://gitlab.com/msberends/AMR #
# #
# LICENCE #
# (c) 2019 Berends MS (m.s.berends@umcg.nl), Luz CF (c.f.luz@umcg.nl) #
# #
# 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. #
# Visit our website for more info: https://msberends.gitlab.io/AMR. #
# ==================================================================== #
context("ab.R")
test_that("as.atc works", {
expect_identical(class(as.atc("amox")), "atc")
expect_true(is.atc(as.atc("amox")))
expect_output(print(as.atc("amox")))
expect_output(print(data.frame(a = as.atc("amox"))))
expect_identical(class(pull(antibiotics, atc)), "atc")
expect_warning(as.atc("Z00ZZ00")) # not yet availatcle in data set
expect_warning(as.atc("UNKNOWN"))
expect_output(print(as.atc("amox")))
})

View File

@ -51,8 +51,7 @@ test_that("counts work", {
# count_df
expect_equal(
septic_patients %>% select(AMX) %>% count_df() %>% pull(Value),
c(septic_patients$AMX %>% count_S(),
septic_patients$AMX %>% count_I(),
c(septic_patients$AMX %>% count_SI(),
septic_patients$AMX %>% count_R())
)
expect_equal(
@ -60,6 +59,12 @@ test_that("counts work", {
c(septic_patients$AMX %>% count_S(),
septic_patients$AMX %>% count_IR())
)
expect_equal(
septic_patients %>% select(AMX) %>% count_df(combine_SI = FALSE) %>% pull(Value),
c(septic_patients$AMX %>% count_S(),
septic_patients$AMX %>% count_I(),
septic_patients$AMX %>% count_R())
)
# warning for speed loss
expect_warning(count_R(as.character(septic_patients$AMC)))

View File

@ -101,8 +101,7 @@ test_that("portions works", {
# portion_df
expect_equal(
septic_patients %>% select(AMX) %>% portion_df() %>% pull(Value),
c(septic_patients$AMX %>% portion_S(),
septic_patients$AMX %>% portion_I(),
c(septic_patients$AMX %>% portion_SI(),
septic_patients$AMX %>% portion_R())
)
expect_equal(
@ -110,6 +109,12 @@ test_that("portions works", {
c(septic_patients$AMX %>% portion_S(),
septic_patients$AMX %>% portion_IR())
)
expect_equal(
septic_patients %>% select(AMX) %>% portion_df(combine_SI = FALSE) %>% pull(Value),
c(septic_patients$AMX %>% portion_S(),
septic_patients$AMX %>% portion_I(),
septic_patients$AMX %>% portion_R())
)
})

View File

@ -54,3 +54,53 @@ test_that("rsi works", {
40)
})
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(septic_patients %>%
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(septic_patients %>%
mutate(amox_disk = as.disk(15)) %>%
select(mo, amox_disk) %>%
as.rsi(guideline = "CLSI") %>%
pull(amox_disk) %>%
is.rsi())
})