Title: | Extend 'tinytest' with 'diffobj' |
---|---|
Description: | The 'tinytest' package offers a light-weight zero-dependency unit-testing framework to which this package adds support of the 'diffobj' package for 'diff'-style comparison of R objects. |
Authors: | Dirk Eddelbuettel and Alton Barbehenn |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.9 |
Built: | 2024-08-11 05:35:17 UTC |
Source: | https://github.com/eddelbuettel/ttdo |
Test for equality with explicit difference
expect_equal_with_diff( current, target, tol = sqrt(.Machine$double.eps), mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_equivalent_with_diff( current, target, tol = sqrt(.Machine$double.eps), ... )
expect_equal_with_diff( current, target, tol = sqrt(.Machine$double.eps), mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_equivalent_with_diff( current, target, tol = sqrt(.Machine$double.eps), ... )
current |
|
target |
|
tol |
|
mode |
|
format |
|
... |
Passed to |
expect_equivalent_with_diff
calls
expect_equal_with_diff
with the extra arguments
check.attributes=FALSE
and use.names=FALSE
A tinytest
object. A tinytest object is a
logical
with attributes holding information about the
test that was run
library(tinytest) using(ttdo) expect_equal_with_diff(1 + 1, 2) # TRUE expect_equal_with_diff(1 - 1, 2) # FALSE expect_equivalent_with_diff(2, c(x=2)) # TRUE expect_equivalent_with_diff(2, c(x=2)) # TRUE
library(tinytest) using(ttdo) expect_equal_with_diff(1 + 1, 2) # TRUE expect_equal_with_diff(1 - 1, 2) # FALSE expect_equivalent_with_diff(2, c(x=2)) # TRUE expect_equivalent_with_diff(2, c(x=2)) # TRUE
Building on the tinytest functions for testing equality with optional enhanced object diffing and additional test feedback through addtional attributes.
expect_equal_xl( current, target, useDiffObj = TRUE, tol = sqrt(.Machine$double.eps), info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_identical_xl( current, target, useDiffObj = TRUE, info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_equivalent_xl( current, target, useDiffObj = TRUE, tol = sqrt(.Machine$double.eps), info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... )
expect_equal_xl( current, target, useDiffObj = TRUE, tol = sqrt(.Machine$double.eps), info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_identical_xl( current, target, useDiffObj = TRUE, info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... ) expect_equivalent_xl( current, target, useDiffObj = TRUE, tol = sqrt(.Machine$double.eps), info = NA_character_, mode = getOption("diffobj.mode", "unified"), format = getOption("diffobj.format", "ansi256"), ... )
current |
|
target |
|
useDiffObj |
|
tol |
|
info |
An additional attribute to pass around with the tinytest object |
mode |
|
format |
|
... |
Passed to |
While tinytest does now support the passing of additional information with the info
field in its tests, they are not yet supported in the as.data.frame.tinytests
method.
A tinytest
object. A tinytest object is a
logical
with attributes holding information about the
test that was run
library(tinytest) using(ttdo) expect_equal_xl(1 + 1, 2, score = 3) # TRUE expect_equal_xl(1 - 1, 2, name = "check 1-1==2", score = 1, totalpts = 2) # FALSE
library(tinytest) using(ttdo) expect_equal_xl(1 + 1, 2, score = 3) # TRUE expect_equal_xl(1 - 1, 2, name = "check 1-1==2", score = 1, totalpts = 2) # FALSE
This method extends the as.data.frame.tinytest
method to handle
arbitrary attributes attached to each tinytest object. You can pass in
the results of a single test (a tinytest object) directly or the results
of one of the run_test_*
functions (a tinytests object).
makeDataFrame(x)
makeDataFrame(x)
x |
a tinytest or tinytests object |
# create a test file in tempdir tests <- " using(ttdo) addOne <- function(x) x + 2 expect_true(addOne(0) > 0) expect_equal(2, addOne(1)) " testfile <- tempfile(pattern = "test_", fileext = ".R") write(tests, testfile) # extract testdir testdir <- dirname(testfile) # run all files starting with 'test' in testdir library(tinytest) out <- run_test_dir(testdir) # # convert results dat <- makeDataFrame(out) dat dat2 <- makeDataFrame(expect_equal_xl(1-1, 2, useDiffObj = FALSE, name = 'subtr', pts = 1))
# create a test file in tempdir tests <- " using(ttdo) addOne <- function(x) x + 2 expect_true(addOne(0) > 0) expect_equal(2, addOne(1)) " testfile <- tempfile(pattern = "test_", fileext = ".R") write(tests, testfile) # extract testdir testdir <- dirname(testfile) # run all files starting with 'test' in testdir library(tinytest) out <- run_test_dir(testdir) # # convert results dat <- makeDataFrame(out) dat dat2 <- makeDataFrame(expect_equal_xl(1-1, 2, useDiffObj = FALSE, name = 'subtr', pts = 1))
Building on the tinytest functions for testing boolean values with additional test feedback through attributes.
expect_true_xl(current, info = NA_character_, ...) expect_false_xl(current, info = NA_character_, ...) expect_null_xl(current, info = NA_character_, ...) expect_silent_xl(current, quiet = TRUE, info = NA_character_, ...) expect_error_xl( current, pattern = ".*", class = "error", info = NA_character_, ... ) expect_warning_xl( current, pattern = ".*", class = "warning", info = NA_character_, strict = FALSE, ... ) expect_message_xl( current, pattern = ".*", class = "message", info = NA_character_, strict = FALSE, ... )
expect_true_xl(current, info = NA_character_, ...) expect_false_xl(current, info = NA_character_, ...) expect_null_xl(current, info = NA_character_, ...) expect_silent_xl(current, quiet = TRUE, info = NA_character_, ...) expect_error_xl( current, pattern = ".*", class = "error", info = NA_character_, ... ) expect_warning_xl( current, pattern = ".*", class = "warning", info = NA_character_, strict = FALSE, ... ) expect_message_xl( current, pattern = ".*", class = "message", info = NA_character_, strict = FALSE, ... )
current |
|
info |
scalar. Optional user-defined message. Must be a single character string. Multiline comments may be separated by "\n". |
... |
Passed to |
quiet |
|
pattern |
|
class |
|
strict |
|
While tinytest does now support the passing of additional information with the info
field in its tests, they are not yet supported in the as.data.frame.tinytests
method.
A tinytest
object. A tinytest object is a
logical
with attributes holding information about the
test that was run
library(tinytest) using(ttdo) expect_true_xl(TRUE, score = 3) # TRUE expect_true_xl(FALSE, name = "check 1-1==2", score = 1, totalpts = 2) # FALSE
library(tinytest) using(ttdo) expect_true_xl(TRUE, score = 3) # TRUE expect_true_xl(FALSE, name = "check 1-1==2", score = 1, totalpts = 2) # FALSE