mirror of
https://github.com/msberends/AMR.git
synced 2025-07-09 11:01:57 +02:00
(v1.6.0.9065) unit tests
This commit is contained in:
@ -22,34 +22,32 @@
|
||||
# Visit our website for the full manual and a complete tutorial about #
|
||||
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
|
||||
# ==================================================================== #
|
||||
|
||||
|
||||
expect_equal(AMR:::percentage(0.25), "25%")
|
||||
expect_equal(AMR:::percentage(0.5), "50%")
|
||||
expect_equal(AMR:::percentage(0.500, digits = 1), "50.0%")
|
||||
expect_equal(AMR:::percentage(0.1234), "12.3%")
|
||||
# round up 0.5
|
||||
# round up 0.5
|
||||
expect_equal(AMR:::percentage(0.0054), "0.5%")
|
||||
expect_equal(AMR:::percentage(0.0055), "0.6%")
|
||||
|
||||
|
||||
expect_equal(AMR:::strrep("A", 5), "AAAAA")
|
||||
expect_equal(AMR:::strrep(c("A", "B"), c(5, 2)), c("AAAAA", "BB"))
|
||||
expect_equal(AMR:::trimws(" test "), "test")
|
||||
expect_equal(AMR:::trimws(" test ", "l"), "test ")
|
||||
expect_equal(AMR:::trimws(" test ", "r"), " test")
|
||||
|
||||
|
||||
expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX")))
|
||||
expect_warning(AMR:::generate_warning_abs_missing(c("AMP", "AMX"), any = TRUE))
|
||||
expect_warning(AMR:::get_column_abx(example_isolates, hard_dependencies = "FUS"))
|
||||
expect_message(AMR:::get_column_abx(example_isolates, soft_dependencies = "FUS"))
|
||||
if (AMR:::pkg_is_available("dplyr")) {
|
||||
|
||||
if (AMR:::pkg_is_available("dplyr")) {
|
||||
expect_warning(AMR:::get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = TRUE))
|
||||
expect_warning(AMR:::get_column_abx(rename(example_isolates, thisone = AMX), amox = "thisone", tmp = "thisone", verbose = FALSE))
|
||||
}
|
||||
|
||||
|
||||
# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this:
|
||||
if (AMR:::pkg_is_available("dplyr")) {
|
||||
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# we rely on "grouped_tbl" being a class of grouped tibbles, so implement a test that checks for this:
|
||||
if (AMR:::pkg_is_available("dplyr")) {
|
||||
expect_true(AMR:::is_null_or_grouped_tbl(example_isolates %>% group_by(hospital_id)))
|
||||
}
|
||||
|
@ -36,11 +36,9 @@ expect_equal(count_R(example_isolates$AMX) + count_I(example_isolates$AMX),
|
||||
expect_equal(suppressWarnings(count_S(example_isolates$AMX)) + count_I(example_isolates$AMX),
|
||||
count_SI(example_isolates$AMX))
|
||||
|
||||
|
||||
# warning for speed loss
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(count_resistant(as.character(example_isolates$AMC)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
|
||||
expect_warning(count_resistant(example_isolates$AMC,
|
||||
as.character(example_isolates$GEN)))
|
||||
|
||||
|
@ -45,6 +45,7 @@ expect_warning(eucast_rules(data.frame(mo = "Escherichia coli", vancomycin = "S"
|
||||
|
||||
expect_identical(colnames(example_isolates),
|
||||
colnames(suppressWarnings(eucast_rules(example_isolates, info = FALSE))))
|
||||
|
||||
expect_stdout(suppressMessages(eucast_rules(example_isolates, info = TRUE)))
|
||||
|
||||
a <- data.frame(mo = c("Klebsiella pneumoniae",
|
||||
@ -84,7 +85,7 @@ if (AMR:::pkg_is_available("dplyr")) {
|
||||
"R")
|
||||
}
|
||||
|
||||
# Azithromycin and Clarythromycin must be equal to Erythromycin
|
||||
# azithromycin and clarythromycin must be equal to Erythromycin
|
||||
a <- suppressWarnings(as.rsi(eucast_rules(data.frame(mo = example_isolates$mo,
|
||||
ERY = example_isolates$ERY,
|
||||
AZM = as.rsi("R"),
|
||||
@ -117,18 +118,21 @@ if (AMR:::pkg_is_available("dplyr")) {
|
||||
expect_stdout(suppressWarnings(eucast_rules(example_isolates, verbose = TRUE, rules = "all", info = TRUE)))
|
||||
|
||||
# AmpC de-repressed cephalo mutants
|
||||
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))),
|
||||
ampc_cephalosporin_resistance = TRUE,
|
||||
info = FALSE)$cefotax,
|
||||
as.rsi(c("S", "R")))
|
||||
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))),
|
||||
ampc_cephalosporin_resistance = NA,
|
||||
info = FALSE)$cefotax,
|
||||
as.rsi(c("S", NA)))
|
||||
|
||||
expect_identical(
|
||||
eucast_rules(data.frame(mo = c("Escherichia coli", "Enterobacter cloacae"),
|
||||
cefotax = as.rsi(c("S", "S"))),
|
||||
|
@ -88,14 +88,12 @@ if (AMR:::pkg_is_available("dplyr")) {
|
||||
example_isolates$AMX %>% proportion_R())
|
||||
)
|
||||
}
|
||||
AMR:::reset_all_thrown_messages()
|
||||
|
||||
expect_warning(proportion_R(as.character(example_isolates$AMC)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(as.character(example_isolates$AMC)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
|
||||
expect_warning(n_rsi(as.character(example_isolates$AMC,
|
||||
example_isolates$GEN)))
|
||||
expect_equal(suppressWarnings(n_rsi(as.character(example_isolates$AMC,
|
||||
@ -120,11 +118,8 @@ expect_identical(suppressWarnings(proportion_S(example_isolates$AMX, minimum = n
|
||||
NA_real_)
|
||||
|
||||
# warning for speed loss
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_R(as.character(example_isolates$GEN)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_I(as.character(example_isolates$GEN)))
|
||||
AMR:::reset_all_thrown_messages()
|
||||
expect_warning(proportion_S(example_isolates$AMC, as.character(example_isolates$GEN)))
|
||||
expect_error(proportion_df(c("A", "B", "C")))
|
||||
expect_error(proportion_df(example_isolates[, "date"]))
|
||||
|
Reference in New Issue
Block a user