Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Chirico committed Jan 29, 2018
1 parent e727345 commit 7c73e5b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
17 changes: 10 additions & 7 deletions R/test.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE) {
if (exists("test.data.table",.GlobalEnv,inherits=FALSE)) {
# package developer
if ("package:data.table" %in% search()) stop("data.table package is loaded. Unload or start a fresh R session.")
d = if (pkg %in% dir()) paste0(getwd(),"/",pkg) else Sys.getenv("CC_DIR")
d = paste0(d, "/inst/tests")
d = if (pkg %in% dir()) file.path(getwd(), pkg) else Sys.getenv("CC_DIR")
d = file.path(d, "inst/tests")
} else {
# R CMD check and user running test.data.table()
d = paste0(getNamespaceInfo("data.table","path"),"/tests")
Expand Down Expand Up @@ -40,13 +40,16 @@ test.data.table <- function(verbose=FALSE, pkg="pkg", silent=FALSE) {
# whichfail = NULL
# .devtesting = TRUE

compactprint <- function(DT, topn=2) {
# essentially toString.default
makeString = function (x) paste(x, collapse = ",")

compactprint <- function(DT, topn=2L) {
tt = vapply_1c(DT,function(x)class(x)[1L])
tt[tt=="integer64"] = "i64"
cn = paste(" [Key=",paste(key(DT),collapse=","),
" Types=",paste(substring(sapply(DT,typeof),1,3),collapse=","),
" Classes=",paste(substring(tt,1,3),collapse=","),
"]",sep="")
tt = substring(tt, 1L, 3L)
cn = paste0(" [Key=",makeString(key(DT)),
" Types=", makeString(substring(sapply(DT, typeof), 1L, 3L)),
" Classes=", makeString(tt), "]")
if (nrow(DT)) {
print(copy(DT)[,(cn):=""], topn=topn)
} else {
Expand Down
35 changes: 35 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -11376,6 +11376,41 @@ test(1869.1, data.table(a = 1:4, short_s4_col), error = 'problem recycling.*try
## i must be a data.table when on is specified
DT = data.table(a = 1:3)
test(1869.2, DT[c(TRUE, FALSE), on = 'coefficients'], error = "not a data.table, but 'on'")
## missing tests for round.IDate
test_dates = c(
"2017-01-05", "2017-08-04", "2017-06-05", "2017-04-15",
"2017-06-11", "2017-10-04", "2017-04-19", "2017-01-11",
"2017-03-08", "2017-10-10"
)
test_dates = as.IDate(test_dates)
test(1869.3, round(test_dates, 'weeks'),
structure(c(17167L, 17377L, 17321L, 17272L, 17328L,
17440L, 17272L, 17174L, 17230L, 17447L),
class = c("IDate", "Date")))
test(1869.4, round(test_dates, 'months'),
structure(c(17167L, 17379L, 17318L, 17257L, 17318L,
17440L, 17257L, 17167L, 17226L, 17440L),
class = c("IDate", "Date")))
test(1869.5, round(test_dates, 'quarters'),
structure(c(17167L, 17348L, 17257L, 17257L, 17257L,
17440L, 17257L, 17167L, 17167L, 17440L),
class = c("IDate", "Date")))
test(1869.6, round(test_dates, 'years'),
structure(c(17167L, 17167L, 17167L, 17167L, 17167L,
17167L, 17167L, 17167L, 17167L, 17167L),
class = c("IDate", "Date")))
test(1869.7, round(test_dates, 'centuries'),
error = 'should be one of')
## missing a test of mday
test(1869.8, mday(test_dates),
c(5L, 4L, 5L, 15L, 11L, 4L, 19L, 11L, 8L, 10L))
## META TEST of helper function compactprint from test.data.table
DT = data.table(a = 1, b = 2, key = 'a')
DT_out = gsub('\\s+$', '', capture.output(compactprint(DT)))
test(1869.9, DT_out,
c(" a b [Key=a Types=dou,dou Classes=num,num]",
"1: 1 2"))


##########################

Expand Down

0 comments on commit 7c73e5b

Please sign in to comment.