expect_equal | R Documentation |
Express expectations
expect_equal( current, target, tolerance = sqrt(.Machine$double.eps), info = NA_character_, ... ) expect_identical(current, target, info = NA_character_) expect_equivalent( current, target, tolerance = sqrt(.Machine$double.eps), info = NA_character_, ... ) expect_true(current, info = NA_character_) expect_false(current, info = NA_character_) expect_silent(current, quiet = TRUE, info = NA_character_) expect_null(current, info = NA_character_) expect_inherits(current, class, info = NA_character_) expect_error( current, pattern = ".*", class = "error", info = NA_character_, ... ) expect_warning( current, pattern = ".*", class = "warning", info = NA_character_, strict = FALSE, ... ) expect_message( current, pattern = ".*", class = "message", info = NA_character_, strict = FALSE, ... ) expect_stdout(current, pattern = ".*", info = NA_character_, ...)
current |
|
target |
|
tolerance |
|
info |
|
... |
passed on to |
quiet |
|
class |
|
pattern |
|
strict |
|
expect_equivalent
calls expect_equal
with the extra
arguments check.attributes=FALSE
and use.names=FALSE
expect_silent
fails when an error or warning is thrown.
expect_inherits
fails when inherits(current,class)
returns FALSE
expect_stdout
Expects that output is written to stdout
,
for example using cat
or print
. Use pattern
to
specify a regular expression matching the output.
A tinytest
object. A tinytest object is a
logical
with attributes holding information about the
test that was run
An overview of tinytest can be found in vignette("using_tinytest")
.
Examples of how tinytest is used in practice can be found in
vignette("tinytest_examples")
Each expect_haha
function can also be called as checkHaha
.
Although the interface is not entirely the same, it is expected that
this makes migration from the RUnit
framework a little easier, for those
who wish to do so.
expect_error
, expect_warning
and expect_message
will
concatenate all messages when multiple exceptions are thrown, before
matching the message to pattern
.
When speccifying regular expression patterns for errors, warnings or messages,
note that message
adds a LF character by default at the end
of the message string.
Other test-functions:
expect_equal_to_reference()
,
expect_length()
,
expect_match()
,
ignore()
expect_equal(1 + 1, 2) # TRUE expect_equal(1 - 1, 2) # FALSE expect_equivalent(2, c(x=2)) # TRUE expect_equal(2, c(x=2)) # FALSE expect_silent(1+1) # TRUE expect_silent(1+"a") # FALSE expect_silent(print("hihi")) # TRUE, nothing goes to screen expect_silent(print("hihi"), quiet=FALSE) # TRUE, and printed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.