Skip to content

Commit

Permalink
added tdf reading tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanderloo committed May 2, 2016
1 parent e747c57 commit dcbaf55
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/tests/testthat/testTCF.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ test_that("read_tcf parses tcf files", {
expect_equal(x@outputfiles,"F")
expect_equal(x@run,TRUE)
})
tryCatch(unlink(f),error=function(e)cat(sprintf("Could not unlinke temporary file %s",f)))
28 changes: 27 additions & 1 deletion pkg/tests/testthat/testTDF.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
testthat::context("Reading TRIM input files")


test_that("reading happy flow",{
f <- tempfile()
# happy flow
writeLines("1 1992 186 1.0000 1
Expand All @@ -13,7 +15,6 @@ writeLines("1 1992 186 1.0000 1
1 2000 0 1.0000 1
1 2001 -1 1.0000 1",con=f)

test_that("reading happy flow",{
dat <- read_tdf(file=f,missing_code=-1L,nsnif=5)
expect_equal(dat[1,],
data.frame(
Expand All @@ -24,8 +25,33 @@ test_that("reading happy flow",{
,covar01=1
))
expect_equal(dat[10,3],NA_integer_)
tryCatch(unlink(f),error=function(e)cat(sprintf("Could not unlinke temporary file %s",f)))
})


test_that("reading with errors",{
f <- tempfile()
writeLines("1 1992 186 1
1 1993 60 1.0000 1
1 1994 39 1.0000 1
1 1995 3 1.0000 1
1 1996 3 1.0000 1
1 1997 0 1.0000 1
1 1998 0 1.0000 1
1 1999 0 1.0000 1
1 2000 0 1.0000 1
1 2001 -1 1.0000 1",con=f)
expect_error(read_tdf(file=f),regexp = "numbers of columns")
expect_warning(read_tdf(textConnection("")),regexp = "no records")
writeLines("1 1992 186
1 1993 60
1 1994 39
1 2001 -1",con=f)
expect_error(read_tdf(file=f),regexp="at least 4")

})





0 comments on commit dcbaf55

Please sign in to comment.