-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-make_linelist.R
63 lines (47 loc) · 1.6 KB
/
test-make_linelist.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
test_that("tests for make_linelist", {
# test errors
msg <- "Must be of type 'data.frame', not 'NULL'."
expect_error(make_linelist(NULL), msg)
msg <- "Must have at least 1 cols, but has 0 cols."
expect_error(make_linelist(data.frame()), msg)
msg <- "Must be element of set {'speed','dist'}, but is"
expect_error(make_linelist(cars, outcome = "bar"), msg, fixed = TRUE)
expect_error(
make_linelist(cars, outcome = "bar", age = "bla"),
"2 assertions failed"
)
msg <- "Use only tags listed in `tags_names()`, or set `allow_extra = TRUE`"
expect_error(
make_linelist(cars, foo = "speed", allow_extra = FALSE),
msg,
fixed = TRUE
)
# test functionalities
expect_identical(tags_defaults(), tags(make_linelist(cars), TRUE))
x <- make_linelist(cars, date_onset = "dist", date_outcome = "speed")
expect_identical(tags(x)$date_onset, "dist")
expect_identical(tags(x)$date_outcome, "speed")
expect_null(tags(x)$outcome)
expect_null(tags(x)$date_reporting)
x <- make_linelist(cars, foo = "speed", bar = "dist", allow_extra = TRUE)
expect_identical(
tags(x, TRUE),
c(tags_defaults(), foo = "speed", bar = "dist")
)
})
test_that("make_linelist() works with dynamic dots", {
expect_identical(
make_linelist(cars, date_onset = "dist", date_outcome = "speed"),
make_linelist(cars, !!!list(date_onset = "dist", date_outcome = "speed"))
)
})
test_that("make_linelist() errors on data.table input", {
dt_cars <- structure(
cars,
class = c("data.table", "data.frame")
)
expect_error(
make_linelist(dt_cars),
"NOT be a data.table"
)
})