mirror of
https://github.com/msberends/AMR.git
synced 2025-07-08 07:51:57 +02:00
unit test read.4d, unselecting freq cols
This commit is contained in:
@ -11,6 +11,8 @@ test_that("frequency table works", {
|
||||
expect_equal(nrow(freq(septic_patients$date)),
|
||||
length(unique(septic_patients$date)))
|
||||
|
||||
expect_output(print(septic_patients %>% freq(age)))
|
||||
expect_output(print(septic_patients %>% freq(age, nmax = 5)))
|
||||
expect_output(print(septic_patients %>% freq(age, nmax = Inf)))
|
||||
expect_output(print(freq(septic_patients$age, nmax = Inf)))
|
||||
expect_output(print(freq(septic_patients$age, nmax = NA)))
|
||||
@ -123,6 +125,12 @@ test_that("frequency table works", {
|
||||
expect_error(septic_patients %>% freq(peni, oxac, clox, amox, amcl,
|
||||
ampi, pita, czol, cfep, cfur))
|
||||
|
||||
# (un)select columns
|
||||
expect_equal(septic_patients %>% freq(hospital_id) %>% select(item) %>% ncol(),
|
||||
1)
|
||||
expect_equal(septic_patients %>% freq(hospital_id) %>% select(-item) %>% ncol(),
|
||||
4)
|
||||
|
||||
# run diff
|
||||
expect_output(print(
|
||||
diff(freq(septic_patients$amcl),
|
||||
|
30
tests/testthat/test-read.4d.R
Normal file
30
tests/testthat/test-read.4d.R
Normal file
@ -0,0 +1,30 @@
|
||||
context("read.4d.R")
|
||||
|
||||
test_that("read 4D works", {
|
||||
|
||||
library(dplyr)
|
||||
test1 <- data.frame(Patientnr = "ABC",
|
||||
MV = "M",
|
||||
Monsternr = "0123",
|
||||
Afnamedat = "10-11-12",
|
||||
Bepaling = "bk",
|
||||
Afd. = "ABC",
|
||||
Spec = "ABC",
|
||||
Matbijz. = "ABC",
|
||||
Mat = "ABC",
|
||||
Mocode = "esccol",
|
||||
PENI = "R",
|
||||
stringsAsFactors = FALSE)
|
||||
tf <- tempfile()
|
||||
write.table(test1, file = tf, quote = F, sep = "\t")
|
||||
|
||||
x <- read.4D(tf, skip = 0)
|
||||
unlink(tf)
|
||||
|
||||
expect_equal(ncol(x), 11)
|
||||
expect_equal(class(x$date_received), "Date")
|
||||
expect_equal(class(x$mo), "mo")
|
||||
expect_equal(as.character(x$mo), "B_ESCHR_COL")
|
||||
expect_equal(is.rsi(x$peni), TRUE)
|
||||
|
||||
})
|
Reference in New Issue
Block a user