AMR/tests/testthat/test-mo_property.R

60 lines
2.7 KiB
R
Raw Normal View History

context("mo_property.R")
test_that("mo_property works", {
2018-09-17 20:53:32 +02:00
expect_equal(mo_phylum("E. coli"), "Proteobacteria")
expect_equal(mo_class("E. coli"), "Gammaproteobacteria")
expect_equal(mo_order("E. coli"), "Enterobacteriales")
expect_equal(mo_family("E. coli"), "Enterobacteriaceae")
expect_equal(mo_genus("E. coli"), "Escherichia")
expect_equal(mo_species("E. coli"), "coli")
2018-09-05 12:21:27 +02:00
expect_equal(mo_subspecies("E. coli"), "")
expect_equal(mo_fullname("E. coli"), "Escherichia coli")
expect_equal(mo_type("E. coli", language = "en"), "Bacteria")
expect_equal(mo_gramstain("E. coli", language = "en"), "Negative rods")
expect_equal(mo_aerobic("E. coli"), TRUE)
2018-09-05 10:51:46 +02:00
expect_equal(mo_shortname("MRSA"), "S. aureus")
expect_equal(mo_shortname("MRSA", Becker = TRUE), "S. aureus")
expect_equal(mo_shortname("MRSA", Becker = "all"), "CoPS")
expect_equal(mo_shortname("S. aga"), "S. agalactiae")
expect_equal(mo_shortname("S. aga", Lancefield = TRUE), "GBS")
# test integrity
library(dplyr)
MOs <- AMR::microorganisms %>% filter(!is.na(mo), nchar(mo) > 3)
expect_identical(MOs$fullname, mo_fullname(MOs$fullname, language = "en"))
mo_clean <- MOs$mo
mo_from_shortname <- as.mo(mo_shortname(mo_clean))
mo_clean <- mo_clean[nchar(mo_from_shortname) == 6 &
!is.na(mo_from_shortname) &
!mo_from_shortname %like% "...SPP"]
mo_from_shortname <- mo_from_shortname[nchar(mo_from_shortname) == 6 &
!is.na(mo_from_shortname) &
!mo_from_shortname %like% "...SPP"]
tb <- tibble(a = substr(mo_clean, 1, 6),
b = mo_from_shortname,
c = a == b,
d = mo_shortname(a),
e = mo_shortname(b),
f = d == e)
expect_gt(sum(tb$c) / nrow(tb), 0.9) # more than 90% of MO code should be identical
expect_identical(sum(tb$f), nrow(tb)) # all shortnames should be identical
# check languages
expect_equal(mo_type("E. coli", language = "de"), "Bakterium")
expect_equal(mo_type("E. coli", language = "nl"), "Bacterie")
expect_equal(mo_gramstain("E. coli", language = "nl"), "Negatieve staven")
expect_output(print(mo_gramstain("E. coli", language = "en")))
expect_output(print(mo_gramstain("E. coli", language = "de")))
expect_output(print(mo_gramstain("E. coli", language = "nl")))
expect_output(print(mo_gramstain("E. coli", language = "es")))
expect_output(print(mo_gramstain("E. coli", language = "pt")))
expect_output(print(mo_gramstain("E. coli", language = "it")))
expect_output(print(mo_gramstain("E. coli", language = "fr")))
expect_error(mo_gramstain("E. coli", language = "UNKNOWN"))
})