Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Lyw unit test #146

Merged
merged 11 commits into from
Jul 10, 2023
71 changes: 71 additions & 0 deletions tests/testthat/test-check_rs_rsdtc_visit_ordinal_error.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
test_that("Function returns true when no errors are present", {

RS<- data.frame(USUBJID = 101:102,
RSDTC=rep(c("2017-01-01T08:25", "2017-01-05T09:25",
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2),
VISITNUM=rep(1:5,2),
VISIT=rep(c("Screening", "Cycle 1", "Cycle 2","Cycle 3","Follow-up"),2),
RSTESTCD="OVRLRESP",
RSEVAL="INVESTIGATOR",
RSSTAT="",
stringsAsFactors=FALSE)

expect_true(check_rs_rsdtc_visit_ordinal_error(RS))
})


test_that("Function returns false when errors are present", {

RS<- data.frame(USUBJID = 101:102,
RSDTC=rep(c("2017-01-01T08:25", "2017-01-05T09:25",
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2),
VISITNUM=rep(1:5,2),
VISIT=rep(c("Screening", "Cycle 1", "Cycle 2","Cycle 3","Follow-up"),2),
RSTESTCD="OVRLRESP",
RSEVAL="INVESTIGATOR",
RSSTAT="",
stringsAsFactors=FALSE)

# adding cases with earlier date
RS$RSDTC[RS$USUBJID == 101 & RS$VISIT == "Cycle 3"] <- "2017-01-02T08:25"
RS$RSDTC[RS$USUBJID == 102 & RS$VISIT == "Cycle 1"] <- "2017-01-01T06:25"

expect_false(check_rs_rsdtc_visit_ordinal_error(RS))
})


test_that("Function returns false when errors are present", {

RS<- data.frame(USUBJID = 101:102,
RSDTC=rep(c("2017-01-01T08:25", "2017-01-05T09:25",
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2),
VISITNUM=rep(1:5,2),
VISIT=rep(c("Screening", "Cycle 1", "Cycle 2","Cycle 3","Follow-up"),2),
RSTESTCD="OVRLRESP",
RSEVAL="INVESTIGATOR",
RSSTAT="",
stringsAsFactors=FALSE)

# Only one value for VISITNUM
RS$VISITNUM = rep(1, 10)

expect_false(check_rs_rsdtc_visit_ordinal_error(RS))
})


test_that("Function returns false when expected column not present", {

RS<- data.frame(USUBJID = 101:102,
RSDTC=rep(c("2017-01-01T08:25", "2017-01-05T09:25",
"2017-01-15T10:25","2017-01-20T08:25","2017-01-25T08:25"), 2),
VISITNUM=rep(1:5,2),
VISIT=rep(c("Screening", "Cycle 1", "Cycle 2","Cycle 3","Follow-up"),2),
RSTESTCD="OVRLRESP",
RSEVAL="INVESTIGATOR",
RSSTAT="",
stringsAsFactors=FALSE)

RS$USUBJID = NULL

expect_false(check_rs_rsdtc_visit_ordinal_error(RS))
})
82 changes: 82 additions & 0 deletions tests/testthat/test-check_sc_dm_eligcrit.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
test_that("Function returns true when no errors are present", {

dm <- data.frame(USUBJID = c(1,2))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest", " "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION",
""),
SCORRES = c("OS", "OS", "", "", "OU", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)

sc$SCORRES[4] = "OS"
expect_true(check_sc_dm_eligcrit(SC=sc, DM=dm))
})


test_that("Function returns false when errors present", {

dm <- data.frame(USUBJID = c(1,2))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest", " "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION",
""),
SCORRES = c("OS", "OS", "", "", "OU", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)

#missing values
dm <- data.frame(USUBJID = c(1,2,3,4))
sc$SCORRES[4] = "OS"


expect_false(check_sc_dm_eligcrit(SC=sc, DM=dm))

})


test_that("Function returns false when expected column not present",{

dm <- data.frame(USUBJID = c(1,2))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest", " "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION",
""),
SCORRES = c("OS", "OS", "", "", "OU", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)


sc$SCORRES <- NULL
expect_false(check_sc_dm_eligcrit(SC=sc, DM=dm))

})


67 changes: 67 additions & 0 deletions tests/testthat/test-check_sc_dm_seyeselc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
test_that("Function returns true when no errors are present" ,{
dm <- data.frame(USUBJID = c(1,2))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest", " "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION", ""),
SCORRES = c("LEFT", "OS", "", "RIGHT", "OD", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)

expect_true(check_sc_dm_seyeselc(SC=sc, DM=dm))
})

test_that("Function returns false when errors present", {
dm <- data.frame(USUBJID = c(1,2,3,4))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION", ""),
SCORRES = c("LEFT", "OS", "", "RIGHT", "", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)

expect_false(check_sc_dm_seyeselc(SC=sc, DM=dm))
})


test_that("Function returns false when expected column not present", {
dm <- data.frame(USUBJID = c(1,2,3,4))
sc <- data.frame(USUBJID = c(1,1,1,2,2,2),
SCTEST = c("Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" ",
"Eye Meeting Eligibility Criteria",
"Focus of Study-Specific Interest",
" "),
SCTESTCD = c("ELIGEYE", "FOCID", "", "ELIGEYE", "FOCID", ""),
SCCAT = c("STUDY EYE SELECTION",
"STUDY EYE SELECTION",
"",
"STUDY EYE SELECTION",
"STUDY EYE SELECTION", ""),
SCORRES = c("LEFT", "OS", "", "RIGHT", "", ""),
SCDTC = rep("2021-01-01", 6),
stringsAsFactors = FALSE)

sc$SCORRES <- NULL
expect_false(check_sc_dm_eligcrit(SC=sc, DM=dm))
})

78 changes: 78 additions & 0 deletions tests/testthat/test-check_ss_ssdtc_alive_dm.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
test_that("Test returns true when no errors present", {
SS <- data.frame(
USUBJID = 1:5,
SSDTC = "2020-01-02",
SSTESTCD = "SURVSTAT",
SSORRES = c("DEAD","DEAD","ALIVE","DEAD","ALIVE"),
VISIT = "WEEK 4"
)


DM <- data.frame(
USUBJID = 1:5,
DTHDTC = "2020-01-03"
)

expect_true(check_ss_ssdtc_alive_dm(SS, DM))

})


test_that("Test returns false when errors present", {

SS <- data.frame(
USUBJID = 1:5,
SSDTC = "2020-01-04",
SSTESTCD = "SURVSTAT",
SSORRES = c("DEAD","DEAD","ALIVE","DEAD","ALIVE"),
VISIT = "WEEK 4"
)

DM <- data.frame(
USUBJID = 1:5,
DTHDTC = c("2020-01-04", "2020-01-05", "2020-01-03", "2020-01-04", "2020-01-05")
)

expect_false(check_ss_ssdtc_alive_dm(SS, DM))

})

test_that("Test returns false when expected column not present - SS", {

SS <- data.frame(
USUBJID = 1:5,
SSDTC = "2020-01-04",
SSTESTCD = "SURVSTAT",
SSORRES = c("DEAD","DEAD","ALIVE","DEAD","ALIVE"),
VISIT = "WEEK 4"
)

DM <- data.frame(
USUBJID = 1:5,
DTHDTC = c("2020-01-04", "2020-01-05", "2020-01-03", "2020-01-04", "2020-01-05")
)

SS$SSTESTCD <- NULL
expect_false(check_ss_ssdtc_alive_dm(SS, DM))

})

test_that("Test returns false when expected column not present - DM", {

SS <- data.frame(
USUBJID = 1:5,
SSDTC = "2020-01-04",
SSTESTCD = "SURVSTAT",
SSORRES = c("DEAD","DEAD","ALIVE","DEAD","ALIVE"),
VISIT = "WEEK 4"
)

DM <- data.frame(
USUBJID = 1:5,
DTHDTC = c("2020-01-04", "2020-01-05", "2020-01-03", "2020-01-04", "2020-01-05")
)

DM$DTHDTC <- NULL
expect_false(check_ss_ssdtc_alive_dm(SS, DM))

})
Loading