mirror of
https://github.com/msberends/AMR.git
synced 2024-12-26 06:46:11 +01:00
extra unit tests
This commit is contained in:
parent
2c8d4cb8bf
commit
a1acb2f3ac
@ -16,7 +16,8 @@ test_that("first isolates work", {
|
|||||||
col_patient_id = "patient_id",
|
col_patient_id = "patient_id",
|
||||||
col_bactid = "bactid",
|
col_bactid = "bactid",
|
||||||
info = FALSE),
|
info = FALSE),
|
||||||
na.rm = TRUE), 1959)
|
na.rm = TRUE),
|
||||||
|
1959)
|
||||||
|
|
||||||
# septic_patients contains 1961 out of 2000 first *weighted* isolates
|
# septic_patients contains 1961 out of 2000 first *weighted* isolates
|
||||||
expect_equal(
|
expect_equal(
|
||||||
@ -31,6 +32,19 @@ test_that("first isolates work", {
|
|||||||
info = TRUE),
|
info = TRUE),
|
||||||
na.rm = TRUE)),
|
na.rm = TRUE)),
|
||||||
1961)
|
1961)
|
||||||
|
# and 1998 when using points
|
||||||
|
expect_equal(
|
||||||
|
suppressWarnings(
|
||||||
|
sum(
|
||||||
|
first_isolate(tbl = septic_patients %>% mutate(keyab = key_antibiotics(.)),
|
||||||
|
col_date = "date",
|
||||||
|
col_patient_id = "patient_id",
|
||||||
|
col_bactid = "bactid",
|
||||||
|
col_keyantibiotics = "keyab",
|
||||||
|
type = "points",
|
||||||
|
info = TRUE),
|
||||||
|
na.rm = TRUE)),
|
||||||
|
1998)
|
||||||
|
|
||||||
# septic_patients contains 1732 out of 2000 first non-ICU isolates
|
# septic_patients contains 1732 out of 2000 first non-ICU isolates
|
||||||
expect_equal(
|
expect_equal(
|
||||||
@ -61,4 +75,21 @@ test_that("first isolates work", {
|
|||||||
info = TRUE),
|
info = TRUE),
|
||||||
na.rm = TRUE),
|
na.rm = TRUE),
|
||||||
1501)
|
1501)
|
||||||
|
# same, but now exclude ICU
|
||||||
|
expect_lt(
|
||||||
|
sum(
|
||||||
|
first_isolate(tbl = mutate(septic_patients,
|
||||||
|
specimen = if_else(row_number() %in% random_rows,
|
||||||
|
"Urine",
|
||||||
|
"Unknown")),
|
||||||
|
col_date = "date",
|
||||||
|
col_patient_id = "patient_id",
|
||||||
|
col_bactid = "bactid",
|
||||||
|
col_specimen = "specimen",
|
||||||
|
filter_specimen = "Urine",
|
||||||
|
col_icu = "ward_icu",
|
||||||
|
icu_exclude = TRUE,
|
||||||
|
info = TRUE),
|
||||||
|
na.rm = TRUE),
|
||||||
|
1501)
|
||||||
})
|
})
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
context("freq.R")
|
context("freq.R")
|
||||||
|
|
||||||
test_that("frequency table works", {
|
test_that("frequency table works", {
|
||||||
expect_equal(nrow(freq(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), as.data.frame = TRUE)), 5)
|
expect_equal(nrow(freq(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))), 5)
|
||||||
expect_equal(nrow(frequency_tbl(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5), as.data.frame = TRUE)), 5)
|
expect_equal(nrow(frequency_tbl(c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5))), 5)
|
||||||
|
|
||||||
# date column of septic_patients should contain 1662 unique dates
|
# date column of septic_patients should contain 1662 unique dates
|
||||||
expect_equal(nrow(freq(septic_patients$date, as.data.frame = TRUE)), 1662)
|
expect_equal(nrow(freq(septic_patients$date)), 1662)
|
||||||
expect_equal(nrow(freq(septic_patients$date, as.data.frame = TRUE)),
|
expect_equal(nrow(freq(septic_patients$date)),
|
||||||
length(unique(septic_patients$date)))
|
length(unique(septic_patients$date)))
|
||||||
|
|
||||||
# int
|
# int
|
||||||
|
@ -2,6 +2,8 @@ context("g.test.R")
|
|||||||
|
|
||||||
test_that("G-test works", {
|
test_that("G-test works", {
|
||||||
|
|
||||||
|
# GOODNESS-OF-FIT
|
||||||
|
|
||||||
# example 1: clearfield rice vs. red rice
|
# example 1: clearfield rice vs. red rice
|
||||||
x <- c(772, 1611, 737)
|
x <- c(772, 1611, 737)
|
||||||
x.expected <- vector2ratio(x, ratio = "1:2:1")
|
x.expected <- vector2ratio(x, ratio = "1:2:1")
|
||||||
@ -16,4 +18,13 @@ test_that("G-test works", {
|
|||||||
expected = 0.01787343,
|
expected = 0.01787343,
|
||||||
tolerance = 0.00000001)
|
tolerance = 0.00000001)
|
||||||
|
|
||||||
|
# INDEPENDENCE
|
||||||
|
|
||||||
|
# this should always yield a p value of around 0
|
||||||
|
x <- matrix(data = round(runif(4) * 100000, 0),
|
||||||
|
ncol = 2,
|
||||||
|
byrow = TRUE)
|
||||||
|
expect_lt(g.test(x),
|
||||||
|
0.0001)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
6
tests/testthat/test-p.symbol.R
Normal file
6
tests/testthat/test-p.symbol.R
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
context("p.symbol.R")
|
||||||
|
|
||||||
|
test_that("P symbol works", {
|
||||||
|
expect_identical(p.symbol(c(0.001, 0.01, 0.05, 0.1, 1)),
|
||||||
|
c("***", "**", "*", ".", " "))
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user