1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-09 19:41:49 +02:00

(v1.4.0.9036) more unit tests

This commit is contained in:
2020-12-11 12:17:23 +01:00
parent 23ddc6004b
commit 2edd3339db
17 changed files with 72 additions and 51 deletions

View File

@ -116,6 +116,6 @@ test_that("EUCAST rules work", {
expect_output(suppressWarnings(eucast_rules(example_isolates %>% mutate(NOR = "S", NAL = "S"), info = TRUE)))
# check verbose output
expect_output(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, info = TRUE)))
expect_output(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, rules = "all", info = TRUE)))
})

View File

@ -57,8 +57,10 @@ test_that("as.mo works", {
expect_equal(as.character(as.mo("Estreptococos grupo B")), "B_STRPT_GRPB")
expect_equal(as.character(as.mo("Group B Streptococci")), "B_STRPT_GRPB")
expect_equal(as.character(suppressWarnings(as.mo("B_STRPT_PNE"))), "B_STRPT_PNMN") # old MO code (<=v0.8.0)
expect_equal(as.character(as.mo(c("mycobacterie", "mycobakterium"))), c("B_MYCBC", "B_MYCBC"))
expect_equal(as.character(as.mo(c("GAS", "GBS"))), c("B_STRPT_GRPA", "B_STRPT_GRPB"))
expect_equal(as.character(as.mo(c("GAS", "GBS", "a MGS", "haemoly strep"))), c("B_STRPT_GRPA", "B_STRPT_GRPB", "B_STRPT_MILL", "B_STRPT_HAEM"))
expect_equal(as.character(as.mo("S. pyo")), "B_STRPT_PYGN") # not Actinomyces pyogenes
@ -110,7 +112,8 @@ test_that("as.mo works", {
rep("B_PRBRK_NODS", 4))
# empty values
expect_identical(as.character(as.mo(c("", NA, NaN))), rep(NA_character_, 3))
expect_identical(as.character(as.mo(c("", " ", NA, NaN))), rep(NA_character_, 4))
expect_identical(as.character(as.mo(" ")), NA_character_)
# too few characters
expect_warning(as.mo("ab"))
@ -203,6 +206,7 @@ test_that("as.mo works", {
# check old names
expect_equal(suppressMessages(as.character(as.mo("Escherichia blattae"))), "B_SHMWL_BLTT")
print(mo_renamed())
expect_equal(suppressMessages(as.character(as.mo(c("E. coli", "Chlamydo psittaci")))), c("B_ESCHR_COLI", "B_CHLMY_PSTT"))
# check uncertain names
expect_equal(suppressMessages(as.character(as.mo("staaur extratest", allow_uncertain = TRUE))), "B_STPHY_AURS")
@ -210,7 +214,7 @@ test_that("as.mo works", {
expect_message(as.mo("e coli extra_text", allow_uncertain = TRUE))
expect_equal(suppressMessages(as.character(as.mo("unexisting aureus", allow_uncertain = 3))), "B_STPHY_AURS")
expect_equal(suppressMessages(as.character(as.mo("unexisting staphy", allow_uncertain = 3))), "B_STPHY_COPS")
expect_equal(suppressMessages(as.character(as.mo("Staphylococcus aureus unexisting", allow_uncertain = 3))), "B_STPHY_AURS_ANRB")
expect_equal(suppressMessages(as.character(as.mo(c("s aur THISISATEST", "Staphylococcus aureus unexisting"), allow_uncertain = 3))), c("B_STPHY_AURS_ANRB", "B_STPHY_AURS_ANRB"))
# predefined reference_df
expect_equal(as.character(as.mo("TestingOwnID",
@ -238,6 +242,9 @@ test_that("as.mo works", {
"Raoultella (here some text) terrigena")))),
c("B_MCRBC_PRXY", "B_STRPT_SUIS", "B_RLTLL_TRRG"))
expect_output(print(mo_uncertainties()))
x <- as.mo("S. aur")
# many hits
expect_output(print(mo_uncertainties()))
# Salmonella (City) are all actually Salmonella enterica spp (City)
expect_equal(suppressMessages(mo_name(c("Salmonella Goettingen", "Salmonella Typhimurium", "Salmonella Group A"))),
@ -285,4 +292,11 @@ test_that("as.mo works", {
expect_warning(x[[1]] <- "invalid code")
expect_warning(c(x[1], "test"))
# ignoring patterns
# frequency tables
if (require("cleaner")) {
expect_s3_class(cleaner::freq(example_isolates$mo), "freq")
}
})

View File

@ -122,6 +122,10 @@ test_that("mo_property works", {
"vanco"),
c(TRUE, FALSE, FALSE))
# with reference data
expect_equal(mo_name("test", reference_df = data.frame(col1 = "test", mo = "B_ESCHR_COLI")),
"Escherichia coli")
library(dplyr)
expect_equal(example_isolates %>% filter(mo_is_gram_negative()) %>% nrow(),
730)