check {svUnit} | R Documentation |
These functions define the assertions in test functions. They are designed to check the result of some test calculation.
checkEquals(target, current, msg = "", tolerance = .Machine$double.eps^0.5, checkNames = TRUE, ...) checkEqualsNumeric(target, current, msg = "", tolerance = .Machine$double.eps^0.5, ...) checkIdentical(target, current, msg = "") checkTrue(expr, msg = "") checkException(expr, msg = "", silent = getOption("svUnit.silentException")) DEACTIVATED(msg = "")
current |
an object created for comparison (not an S4 class object). |
target |
a target object as reference for comparison. |
msg |
an optional (short!) message to document a test. This message is stored in the log and printed in front of each test report. |
tolerance |
numeric >= 0. A numeric check does not fail if differences are smaller than ‘tolerance’. |
checkNames |
flag, if |
expr |
syntactically valid R expression which can be evaluated and must
return a logical vector ( |
silent |
flag passed on to try, which determines if the error message
generated by the checked function is displayed at the R console. By default,
it is |
... |
optional arguments passed to |
These check functions are equivalent to various methods of the class
junit.framework.Assert of Java junit framework. They should be code-compatible
with functions of same name in 'RUnit' 0.4.17, except for checkTrue()
that is vectorized here, but accept only a scalar result in 'RUnit'. For
scalar test, the behaviour of the function is the same in both packages.
See svTest()
for examples of utilisation of these functions in actual
test cases attached to R objects.
See also the note about S4 objects in the checkTrue()
online help of
the 'RUnit' package.
TRUE
if the test succeeds, FALSE
if it fails, possibly with a
'result' attribute containing more information about the problem. This is
very different from corresponding functions in 'RUnit' that stop with an
error in case of test failure. Consequently, current functions do not require
the complex evaluation framework designed in 'RUnit' for that reason.
Philippe Grosjean <phgrosjean@sciviews.org> has adapted interface in 'RUnit' by Thomas Konig, Klaus Junemann & Matthias Burger, recoded it, and ported it to 'svUnit'
svTest
, Log
,
guiTestReport
, checkTrue
clearLog() # Clear the svUnit log ## All these tests are correct (checkEquals(c("A", "B", "C"), LETTERS[1:3])) (checkEqualsNumeric(1:10, seq(1, 10))) (checkIdentical(iris[1:50, ], iris[iris$Species == "setosa",])) (checkTrue(1 < 2)) (checkException(log("a"))) Log() # See what's recorded in the log ## ... but these ones fail (checkEquals("A", LETTERS[1:3])) (checkEqualsNumeric(2:11, seq(1, 10))) (checkIdentical(iris[1:49, ], iris[iris$Species == "setosa",])) (checkTrue(1 > 2)) (checkException(log(1))) Log() # See what's recorded in the log ## Create a test function and run it foo <- function(x, y = 2) return(x * y) test(foo) <- function () { #DEACTIVATED() checkEqualsNumeric(5, foo(2)) checkEqualsNumeric(6, foo(2, 3)) checkTrue(is.test(foo)) checkTrue(is.test(test(foo))) checkIdentical(test(foo), attr(foo, "test")) checkException(foo("b")) checkException(foo(2, "a")) } (runTest(foo)) ## Of course, everything is recorded in the log Log() clearLog()