mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 16:42:10 +02:00
(v1.4.0.9039) more unit tests
This commit is contained in:
@ -92,4 +92,11 @@ test_that("counts work", {
|
||||
expect_error(count_df(c("A", "B", "C")))
|
||||
expect_error(count_df(example_isolates[, "date"]))
|
||||
|
||||
# grouping in rsi_calc_df() (= backbone of rsi_df())
|
||||
expect_true("hospital_id" %in% (example_isolates %>%
|
||||
group_by(hospital_id) %>%
|
||||
select(hospital_id, AMX, CIP, gender) %>%
|
||||
rsi_df() %>%
|
||||
colnames()))
|
||||
|
||||
})
|
||||
|
@ -39,7 +39,12 @@ test_that("disk works", {
|
||||
expect_s3_class(c(x[1], x[9]), "disk")
|
||||
expect_s3_class(unique(x[1], x[9]), "disk")
|
||||
expect_warning(as.disk("INVALID VALUE"))
|
||||
x[2] <- 32
|
||||
expect_s3_class(x, "disk")
|
||||
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(plot(as.disk(c(10, 20, 40))))
|
||||
|
||||
expect_output(print(as.disk(12)))
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
expect_output(print(tibble(d = as.disk(12))))
|
||||
|
@ -150,6 +150,8 @@ test_that("first isolates work", {
|
||||
col_date = "non-existing col",
|
||||
col_mo = "mo"))
|
||||
|
||||
require("dplyr")
|
||||
|
||||
# look for columns itself
|
||||
expect_message(first_isolate(example_isolates))
|
||||
expect_message(first_isolate(example_isolates %>%
|
||||
@ -166,6 +168,14 @@ test_that("first isolates work", {
|
||||
first_isolate(col_date = "date",
|
||||
col_mo = "mo",
|
||||
col_patient_id = "patient_id"))
|
||||
|
||||
# support for WHONET
|
||||
expect_message(example_isolates %>%
|
||||
select(-patient_id) %>%
|
||||
mutate(`First name` = "test",
|
||||
`Last name` = "test",
|
||||
Sex = "Female") %>%
|
||||
first_isolate(info = TRUE))
|
||||
|
||||
# missing dates should be no problem
|
||||
df <- example_isolates
|
||||
@ -203,6 +213,9 @@ test_that("first isolates work", {
|
||||
# notice that all mo's are distinct, so all are TRUE
|
||||
expect_true(all(example_isolates %pm>%
|
||||
pm_distinct(mo, .keep_all = TRUE) %pm>%
|
||||
first_isolate() == TRUE))
|
||||
first_isolate(info = TRUE) == TRUE))
|
||||
|
||||
# only one isolate, so return fast
|
||||
expect_true(first_isolate(data.frame(mo = "Escherichia coli", date = Sys.Date(), patient = "patient"), info = TRUE))
|
||||
|
||||
})
|
||||
|
@ -31,8 +31,15 @@ test_that("`like` works", {
|
||||
|
||||
expect_true("test" %like% "test")
|
||||
expect_false("test" %like_case% "TEST")
|
||||
expect_true(factor("test") %like% factor("t"))
|
||||
expect_true(factor("test") %like% "t")
|
||||
expect_true("test" %like% factor("t"))
|
||||
|
||||
expect_true(as.factor("test") %like% "TEST")
|
||||
expect_identical(factor(c("Test case", "Something different", "Yet another thing")) %like% c("case", "diff", "yet"),
|
||||
c(TRUE, TRUE, TRUE))
|
||||
expect_identical("test" %like% c("t", "e", "s", "t"),
|
||||
c(TRUE, TRUE, TRUE, TRUE))
|
||||
expect_identical(factor("test") %like% factor(c("t", "e", "s", "t")),
|
||||
c(TRUE, TRUE, TRUE, TRUE))
|
||||
})
|
||||
|
@ -43,9 +43,11 @@ test_that("mic works", {
|
||||
expect_s3_class(x[[1]], "mic")
|
||||
expect_s3_class(c(x[1], x[9]), "mic")
|
||||
expect_s3_class(unique(x[1], x[9]), "mic")
|
||||
expect_s3_class(droplevels(c(x[1], x[9])), "mic")
|
||||
x[2] <- 32
|
||||
expect_s3_class(x, "mic")
|
||||
expect_warning(as.mic("INVALID VALUE"))
|
||||
|
||||
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
expect_silent(barplot(as.mic(c(1, 2, 4, 8))))
|
||||
expect_silent(plot(as.mic(c(1, 2, 4, 8))))
|
||||
@ -56,4 +58,7 @@ test_that("mic works", {
|
||||
"<NA>" = "0",
|
||||
"Min." = "2",
|
||||
"Max." = "8"), class = c("summaryDefault", "table")))
|
||||
|
||||
library(dplyr, warn.conflicts = FALSE)
|
||||
expect_output(print(tibble(m = as.mic(2:4))))
|
||||
})
|
||||
|
@ -49,7 +49,18 @@ test_that("PCA works", {
|
||||
expect_s3_class(pca_model, "pca")
|
||||
|
||||
pdf(NULL) # prevent Rplots.pdf being created
|
||||
|
||||
ggplot_pca(pca_model, ellipse = TRUE)
|
||||
ggplot_pca(pca_model, arrows_textangled = FALSE)
|
||||
|
||||
if (require("dplyr")) {
|
||||
resistance_data <- example_isolates %>%
|
||||
group_by(order = mo_order(mo),
|
||||
genus = mo_genus(mo)) %>%
|
||||
summarise_if(is.rsi, resistance, minimum = 0)
|
||||
pca_result <- resistance_data %>%
|
||||
pca(AMC, CXM, CTX, CAZ, GEN, TOB, TMP, "SXT")
|
||||
expect_s3_class(pca_result, "prcomp")
|
||||
ggplot_pca(pca_result, ellipse = TRUE)
|
||||
ggplot_pca(pca_result, ellipse = FALSE, arrows_textangled = FALSE, scale = FALSE)
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user