|
a |
|
b/tests/testthat/test-longlagsettings.R |
|
|
1 |
context("longlagsettings") |
|
|
2 |
test_that("LongLagSettings",{ |
|
|
3 |
|
|
|
4 |
expect_error(LongLagSettings(ndays=-1)) |
|
|
5 |
expect_error(LongLagSettings(ndays=c(1,4))) |
|
|
6 |
expect_error(LongLagSettings(ndays=4,visitschedule=-2)) |
|
|
7 |
expect_error(LongLagSettings(ndays=4,visitschedule=2,analysis.date="dsc")) |
|
|
8 |
}) |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
test_that("DealWithReportingLag",{ |
|
|
12 |
|
|
|
13 |
d <- data.frame(subject=1:10, |
|
|
14 |
rand.date=rep("2015-01-01",10), |
|
|
15 |
has.event=c(1,rep(0,9)), |
|
|
16 |
withdrawn=c(0,1,rep(0,8)), |
|
|
17 |
time=seq(10,100,10)) |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
my.data <- EventData(data=d, |
|
|
21 |
subject="subject", |
|
|
22 |
rand.date="rand.date", |
|
|
23 |
has.event="has.event", |
|
|
24 |
withdrawn="withdrawn", |
|
|
25 |
time="time") |
|
|
26 |
|
|
|
27 |
indat <- my.data@subject.data |
|
|
28 |
expect_equal(indat,DealWithReportingLag(indat,longlagsettings=NULL)) |
|
|
29 |
|
|
|
30 |
lls <- LongLagSettings(ndays=20,toWithdraw=TRUE) |
|
|
31 |
new.indat <- DealWithReportingLag(indat,lls) |
|
|
32 |
|
|
|
33 |
expect_equal(seq(10,100,10),new.indat$time) |
|
|
34 |
expect_equal(c(1,rep(0,9)),new.indat$has.event) |
|
|
35 |
expect_equal(c(0,rep(1,6),0,0,0),new.indat$withdrawn) |
|
|
36 |
|
|
|
37 |
lls <- LongLagSettings(ndays=60,toWithdraw=FALSE,analysis.date ="2015-05-01") |
|
|
38 |
new.indat <- DealWithReportingLag(indat,lls) |
|
|
39 |
|
|
|
40 |
expect_equal(c(10,20,rep(121,4),70,80,90,100),new.indat$time) |
|
|
41 |
expect_equal(c(1,rep(0,9)),new.indat$has.event) |
|
|
42 |
expect_equal(c(0,1,rep(0,8)),new.indat$withdrawn) |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
}) |