Skip to content

Commit 97c6ff4

Browse files
revert
1 parent 9e871d4 commit 97c6ff4

File tree

3 files changed

+4
-156
lines changed

3 files changed

+4
-156
lines changed

R/test.data.table.R

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test.data.table = function(script="tests.Rraw", verbose=FALSE, pkg=".", silent=F
3535
if (identical(script,"*.Rraw")) {
3636
# nocov start
3737
scripts = dir(fulldir, "*.Rraw.*")
38-
scripts = scripts[!grepl("bench|other|manual", scripts)]
38+
scripts = scripts[!grepl("bench|other", scripts)]
3939
scripts = gsub("[.]bz2$","",scripts)
4040
return(sapply(scripts, function(fn) {
4141
err = try(test.data.table(script=fn, verbose=verbose, pkg=pkg, silent=silent, showProgress=showProgress, testPattern=testPattern))
@@ -580,89 +580,3 @@ test = function(num,x,y=TRUE,error=NULL,warning=NULL,message=NULL,output=NULL,no
580580
}
581581

582582
anyNonAscii = function(x) anyNA(iconv(x, to="ASCII")) # nocov
583-
584-
# nocov start
585-
is.AsIs = function(x) inherits(x, "AsIs")
586-
benchmark = function(num, expr, limit, tolerance=0.025, verbose=FALSE) {
587-
588-
.test.data.table = exists("nfail", parent.frame()) # test() can be used inside functions defined in tests.Rraw, so inherits=TRUE (default) here
589-
numStr = sprintf("%.8g", num)
590-
if (.test.data.table) {
591-
prevtest = get("prevtest", parent.frame())
592-
nfail = get("nfail", parent.frame())
593-
whichfail = get("whichfail", parent.frame())
594-
assign("ntest", get("ntest", parent.frame()) + 1L, parent.frame(), inherits=TRUE) # bump number of tests run
595-
lasttime = get("lasttime", parent.frame())
596-
timings = get("timings", parent.frame())
597-
memtest = get("memtest", parent.frame())
598-
inittime = get("inittime", parent.frame())
599-
filename = get("filename", parent.frame())
600-
foreign = get("foreign", parent.frame())
601-
showProgress = get("showProgress", parent.frame())
602-
time = nTest = NULL # to avoid 'no visible binding' note
603-
on.exit( {
604-
now = proc.time()[3L]
605-
took = now-lasttime # so that prep time between tests is attributed to the following test
606-
assign("lasttime", now, parent.frame(), inherits=TRUE)
607-
timings[ as.integer(num), `:=`(time=time+took, nTest=nTest+1L), verbose=FALSE ]
608-
} )
609-
if (showProgress)
610-
cat("\rRunning benchmark id", numStr, " ")
611-
} else {
612-
# not `test.data.table` but developer running tests manually; i.e. `cc(F); test(...)`
613-
memtest = FALSE
614-
filename = NA_character_
615-
foreign = FALSE
616-
showProgress = FALSE
617-
}
618-
619-
sub.expr = substitute(expr)
620-
stopifnot(is.call(sub.expr))
621-
l = if (limit.call<-is.call(sub.limit<-substitute(limit))) system.time(limit)[["elapsed"]]
622-
else if (is.numeric(limit)) limit
623-
else stop("limit must be constant numeric or a call to time it")
624-
625-
t = system.time(expr)[["elapsed"]]
626-
627-
fail = FALSE
628-
if (.test.data.table) {
629-
if (num<prevtest+0.0000005) {
630-
cat("Test id", numStr, "is not in increasing order\n")
631-
fail = TRUE
632-
}
633-
assign("prevtest", num, parent.frame(), inherits=TRUE)
634-
}
635-
if (!fail) {
636-
if (length(tolerance)==1L) {
637-
fail = if (is.AsIs(tolerance)) {
638-
t > l+tolerance
639-
} else {
640-
t > l*(1+tolerance)
641-
}
642-
} else if (length(tolerance)==2L) { ## absolute difference, test 655
643-
if (tolerance[1] >= tolerance[2])
644-
stop("invalid use of tolerance argument, first element must be smaller than second one, first usually being negative and second positive")
645-
fail = if (is.AsIs(tolerance)) {
646-
t < l+tolerance[1] || t > l+tolerance[2]
647-
} else {
648-
t < l*(1+tolerance[1L]) || t > l*(1+tolerance[2])
649-
}
650-
} else stop("tolerance must be length 1 or 2")
651-
if (fail || verbose) {
652-
cat(sprintf("Benchmark %s %scheck that expression:\n> ",
653-
numStr, if (fail) "failed to " else ""))
654-
print(sub.expr)
655-
cat("# elapsed: ", t, "\n", sep="")
656-
cat(sprintf("computes within given limit and tolerance (%s):\n> ",
657-
paste(sprintf("%.3f%s", tolerance, if (is.AsIs(tolerance)) "s" else ""), collapse=",")))
658-
if (limit.call) print(sub.limit) else cat(limit, "\n", sep="")
659-
cat("# elapsed: ", l, "\n", sep="")
660-
}
661-
}
662-
if (fail && .test.data.table) {
663-
assign("nfail", nfail+1L, parent.frame(), inherits=TRUE)
664-
assign("whichfail", c(whichfail, numStr), parent.frame(), inherits=TRUE)
665-
}
666-
invisible(!fail)
667-
}
668-
# nocov end

inst/tests/manual.Rraw

Lines changed: 0 additions & 60 deletions
This file was deleted.

man/test.Rd

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
\name{test}
22
\alias{test}
3-
\alias{benchmark}
4-
\title{ Test assertions for equality, exceptions and console output or call elapsed timing }
3+
\title{ Test assertions for equality, exceptions and console output }
54
\description{
6-
\code{test} is an internal testing function used in \code{data.table} test scripts that are run by \code{\link{test.data.table}}. \code{benchmark} is a very similar function to \code{test} function but it does verify if provided expression computes within expected time.
5+
An internal testing function used in \code{data.table} test scripts that are run by \code{\link{test.data.table}}.
76
}
87
\usage{
98
test(num, x, y = TRUE,
109
error = NULL, warning = NULL, message = NULL,
11-
output = NULL, notOutput = NULL, ignore.warning = NULL)
10+
output = NULL, notOutput = NULL, ignore.warning = NULL,
1211
options = NULL, env = NULL)
13-
benchmark(num, expr, limit, tolerance=0.025, verbose=FALSE)
1412
}
1513
\arguments{
1614
\item{num}{ A unique identifier for a test, helpful in identifying the source of failure when testing is not working. Currently, we use a manually-incremented system with tests formatted as \code{n.m}, where essentially \code{n} indexes an issue and \code{m} indexes aspects of that issue. For the most part, your new PR should only have one value of \code{n} (scroll to the end of \code{inst/tests/tests.Rraw} to see the next available ID) and then index the tests within your PR by increasing \code{m}. Note -- \code{n.m} is interpreted as a number, so \code{123.4} and \code{123.40} are actually the same -- please \code{0}-pad as appropriate. Test identifiers are checked to be in increasing order at runtime to prevent duplicates being possible. }
@@ -24,10 +22,6 @@ benchmark(num, expr, limit, tolerance=0.025, verbose=FALSE)
2422
\item{ignore.warning}{ A single character string. Any warnings emitted by \code{x} that contain this string are dropped. Remaining warnings are compared to the expected \code{warning} as normal. }
2523
\item{options}{ A named list of options to set for the duration of the test. Any code evaluated during this call to \code{test()} (usually, \code{x}, or maybe \code{y}) will run with the named options set, and the original options will be restored on return. This is a named list since different options can have different types in general, but in typical usage, only one option is set at a time, in which case a named vector is also accepted. }
2624
\item{env}{ A named list of environment variables to set for the duration of the test, much like \code{options}. A list entry set to \code{NULL} will unset (i.e., \code{\link{Sys.unsetenv}}) the corresponding variable. }
27-
\item{expr}{ An expression to be timed by \code{benchmark} function. }
28-
\item{limit}{ An expression that \code{expr} should be compared to, or a constant numeric to compared to. Must not be a variable. }
29-
\item{tolerance}{ An extra tolerance ratio to be applied to time. When provided as numeric it will be used to multiply \code{limit} argument, default value \code{0.025} extends the limit value by 2.5 percent. To specify exact number of seconds to \code{tolerance} one may use \code{AsIs} class object, so \code{I(2)} will specify tolerance of 2 seconds. The argument can take a length 2 vector as well, to specify range of expected timing, to be used to compare absolute difference of \code{expr} and \code{limit}. In such case, usually first argument will be a negative one and second positive, for example \code{c(-0.2, 0.2)} will check if time of \code{expr} is equal to time of \code{limit} +/- 20 percent. }
30-
\item{verbose}{ Logical scalar, when \code{TRUE} then \code{benchmark} function will print timings to console. }
3125
}
3226
\note{
3327
\code{NA_real_} and \code{NaN} are treated as equal, use \code{identical} if distinction is needed. See examples below.

0 commit comments

Comments
 (0)