Skip to content

Commit 8a9e727

Browse files
committed
move tests
1 parent 71b21ab commit 8a9e727

File tree

4 files changed

+167
-789
lines changed

4 files changed

+167
-789
lines changed

R/test.data.table.R

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,37 @@ gc_mem = function() {
361361
# nocov end
362362
}
363363

364-
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL,env=NULL) {
364+
test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,notOutput=NULL,ignore.warning=NULL,options=NULL,env=NULL,levels=NULL) {
365+
# if levels is provided, test across multiple optimization levels
366+
if (!is.null(levels)) {
367+
cl = match.call()
368+
cl$levels = NULL # Remove levels from the recursive call
369+
370+
vector_params = c("error", "warning", "message", "output", "notOutput", "ignore.warning")
371+
# Check if y was explicitly provided (not just the default)
372+
y_provided = !missing(y)
373+
compare = !y_provided && length(levels)>1L && !any(vapply_1b(vector_params, function(p) length(get(p, envir=environment())) > 0L))
374+
375+
for (i in seq_along(levels)) {
376+
cl$num = num + (i - 1L) * 1e-6
377+
opt_level = list(datatable.optimize = levels[i])
378+
cl$options = if (!is.null(options)) c(as.list(options), opt_level) else opt_level
379+
for (p in vector_params) {
380+
val = get(p, envir=environment())
381+
if (length(val) > 0L) {
382+
cl[[p]] = val[((i - 1L) %% length(val)) + 1L] # ccycle through values if fewer than levels
383+
} else if (p %in% names(cl)) {
384+
cl[[p]] = NULL
385+
}
386+
}
387+
388+
if (compare && i == 1L) cl$y = eval(cl$x, parent.frame())
389+
eval(cl, parent.frame())
390+
}
391+
return(invisible())
392+
}
393+
394+
# print(match.call())
365395
if (!is.null(env)) {
366396
old = Sys.getenv(names(env), names=TRUE, unset=NA)
367397
to_unset = !lengths(env)

inst/tests/benchmark.Rraw

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,13 @@ DT = data.table(A=1:10,B=rnorm(10),C=paste("a",1:100010,sep=""))
190190
test(301.1, nrow(DT[,sum(B),by=C])==100010)
191191

192192
# Test := by key, and that := to the key by key unsets the key. Make it non-trivial in size too.
193-
local({
194-
old = options(datatable.optimize=0L); on.exit(options(old))
195-
set.seed(1)
196-
DT = data.table(a=sample(1:100, 1e6, replace=TRUE), b=sample(1:1000, 1e6, replace=TRUE), key="a")
197-
test(637.1, DT[, m:=sum(b), by=a][1:3], data.table(a=1L, b=c(156L, 808L, 848L), m=DT[J(1), sum(b)], key="a"))
198-
test(637.2, key(DT[J(43L), a:=99L]), NULL)
199-
setkey(DT, a)
200-
test(637.3, key(DT[, a:=99L, by=a]), NULL)
201-
})
202-
local({
203-
options(datatable.optimize=2L); on.exit(options(old))
204-
set.seed(1)
205-
DT = data.table(a=sample(1:100, 1e6, replace=TRUE), b=sample(1:1000, 1e6, replace=TRUE), key="a")
206-
test(638.1, DT[, m:=sum(b), by=a][1:3], data.table(a=1L, b=c(156L, 808L, 848L), m=DT[J(1), sum(b)], key="a"))
207-
test(638.2, key(DT[J(43L), a:=99L]), NULL)
208-
setkey(DT,a)
209-
test(638.3, key(DT[, a:=99L, by=a]), NULL)
210-
})
193+
set.seed(1)
194+
DT = data.table(a=sample(1:100, 1e6, replace=TRUE), b=sample(1:1000, 1e6, replace=TRUE), key="a")
195+
opt = c(0L,2L)
196+
test(637.1, levels=opt, copy(DT)[, m:=sum(b), by=a][1:3], data.table(a=1L, b=c(156L, 808L, 848L), m=DT[J(1), sum(b)], key="a"))
197+
test(637.2, levels=opt, key(copy(DT)[J(43L), a:=99L]), NULL)
198+
setkey(DT, a)
199+
test(637.3, levels=opt, key(copy(DT)[, a:=99L, by=a]), NULL)
211200

212201
# Test X[Y] slowdown, #2216
213202
# Many minutes in 1.8.2! Now well under 1s, but 10s for very wide tolerance for CRAN. We'd like CRAN to tell us if any changes

0 commit comments

Comments
 (0)