diff --git a/tests/testthat/test-first_isolates.R b/tests/testthat/test-first_isolates.R index 4a3e62c9..1079e5c0 100755 --- a/tests/testthat/test-first_isolates.R +++ b/tests/testthat/test-first_isolates.R @@ -16,7 +16,8 @@ test_that("first isolates work", { col_patient_id = "patient_id", col_bactid = "bactid", info = FALSE), - na.rm = TRUE), 1959) + na.rm = TRUE), + 1959) # septic_patients contains 1961 out of 2000 first *weighted* isolates expect_equal( @@ -31,6 +32,19 @@ test_that("first isolates work", { info = TRUE), na.rm = TRUE)), 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 expect_equal( @@ -61,4 +75,21 @@ test_that("first isolates work", { info = TRUE), na.rm = TRUE), 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) }) diff --git a/tests/testthat/test-freq.R b/tests/testthat/test-freq.R index 18099652..27f38b5d 100755 --- a/tests/testthat/test-freq.R +++ b/tests/testthat/test-freq.R @@ -1,12 +1,12 @@ context("freq.R") 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(frequency_tbl(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))), 5) # 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, as.data.frame = TRUE)), + expect_equal(nrow(freq(septic_patients$date)), 1662) + expect_equal(nrow(freq(septic_patients$date)), length(unique(septic_patients$date))) # int diff --git a/tests/testthat/test-g.test.R b/tests/testthat/test-g.test.R index 14febb54..5b601452 100644 --- a/tests/testthat/test-g.test.R +++ b/tests/testthat/test-g.test.R @@ -2,6 +2,8 @@ context("g.test.R") test_that("G-test works", { + # GOODNESS-OF-FIT + # example 1: clearfield rice vs. red rice x <- c(772, 1611, 737) x.expected <- vector2ratio(x, ratio = "1:2:1") @@ -16,4 +18,13 @@ test_that("G-test works", { expected = 0.01787343, 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) + }) diff --git a/tests/testthat/test-p.symbol.R b/tests/testthat/test-p.symbol.R new file mode 100644 index 00000000..8b40f351 --- /dev/null +++ b/tests/testthat/test-p.symbol.R @@ -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("***", "**", "*", ".", " ")) +})