1
0
mirror of https://github.com/msberends/AMR.git synced 2024-12-26 18:06:11 +01:00

add unit tests

This commit is contained in:
dr. M.S. (Matthijs) Berends 2018-07-17 11:18:36 +02:00
parent a5a4354651
commit 967ee86757
2 changed files with 53 additions and 4 deletions

View File

@ -18,6 +18,7 @@ test_that("G-test works", {
expected = 0.01787343, expected = 0.01787343,
tolerance = 0.00000001) tolerance = 0.00000001)
# INDEPENDENCE # INDEPENDENCE
x <- matrix(data = round(runif(4) * 100000, 0), x <- matrix(data = round(runif(4) * 100000, 0),
@ -26,4 +27,8 @@ test_that("G-test works", {
expect_lt(g.test(x)$p.value, expect_lt(g.test(x)$p.value,
1) 1)
expect_warning(g.test(x = c(772, 1611, 737),
y = c(780, 1560, 780),
rescale.p = TRUE))
}) })

View File

@ -35,12 +35,56 @@ test_that("resistance works", {
}) })
test_that("old rsi works", {
# amox resistance in `septic_patients` should be around 53.86%
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
expect_equal(rsi(septic_patients$amox), 0.5756, tolerance = 0.0001)
expect_equal(rsi_df(septic_patients,
ab = "amox",
info = TRUE),
0.5756,
tolerance = 0.0001)
# pita+genta susceptibility around 98.09%
expect_equal(rsi(septic_patients$pita,
septic_patients$gent,
interpretation = "S",
info = TRUE),
0.9809,
tolerance = 0.0001)
expect_equal(rsi_df(septic_patients,
ab = c("pita", "gent"),
interpretation = "S",
info = TRUE),
0.9809,
tolerance = 0.0001)
# more than 2 not allowed
expect_error(rsi_df(septic_patients,
ab = c("mero", "pita", "gent"),
interpretation = "IS",
info = TRUE))
# count of cases
expect_equal(septic_patients %>%
group_by(hospital_id) %>%
summarise(cipro_S = rsi(cipr, interpretation = "S",
as_percent = TRUE, warning = FALSE),
cipro_n = n_rsi(cipr),
genta_S = rsi(gent, interpretation = "S",
as_percent = TRUE, warning = FALSE),
genta_n = n_rsi(gent),
combination_S = rsi(cipr, gent, interpretation = "S",
as_percent = TRUE, warning = FALSE),
combination_n = n_rsi(cipr, gent)) %>%
pull(combination_n),
c(138, 474, 170, 464, 183))
})
test_that("prediction of rsi works", { test_that("prediction of rsi works", {
amox_R <- septic_patients %>% amox_R <- septic_patients %>%
filter(bactid == "ESCCOL") %>% filter(bactid == "ESCCOL") %>%
rsi_predict(col_ab = "amox", rsi_predict(col_ab = "amox",
col_date = "date", col_date = "date",
info = FALSE) %>% info = TRUE) %>%
pull("probR") pull("probR")
# amox resistance will decrease using dataset `septic_patients` # amox resistance will decrease using dataset `septic_patients`
expect_true(amox_R[2] > amox_R[20]) expect_true(amox_R[2] > amox_R[20])
@ -65,13 +109,13 @@ test_that("prediction of rsi works", {
model = "INVALID MODEL", model = "INVALID MODEL",
col_ab = "amox", col_ab = "amox",
col_date = "date", col_date = "date",
info = FALSE)) info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"), expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
col_ab = "NOT EXISTING COLUMN", col_ab = "NOT EXISTING COLUMN",
col_date = "date", col_date = "date",
info = FALSE)) info = TRUE))
expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"), expect_error(rsi_predict(tbl = filter(septic_patients, bactid == "ESCCOL"),
col_ab = "amox", col_ab = "amox",
col_date = "NOT EXISTING COLUMN", col_date = "NOT EXISTING COLUMN",
info = FALSE)) info = TRUE))
}) })