| equality-expectations | R Documentation |
These functions provide two levels of strictness when comparing a
computation to a reference value. expect_identical() is the baseline;
expect_equal() relaxes the test to ignore small numeric differences.
In the 2nd edition, expect_identical() uses identical() and
expect_equal uses all.equal(). In the 3rd edition, both functions use
waldo. They differ only in that
expect_equal() sets tolerance = testthat_tolerance() so that small
floating point differences are ignored; this also implies that (e.g.) 1
and 1L are treated as equal.
expect_equal(
object,
expected,
...,
tolerance = if (edition_get() >= 3) testthat_tolerance(),
info = NULL,
label = NULL,
expected.label = NULL
)
expect_identical(
object,
expected,
info = NULL,
label = NULL,
expected.label = NULL,
...
)
object, expected |
Computation and value to compare it to. Both arguments supports limited unquoting to make it easier to generate readable failures within a function or for loop. See quasi_label for more details. |
... |
3e: passed on to 2e: passed on to |
tolerance |
3e: passed on to 2e: passed on to |
info |
Extra information to be included in the message. This argument is soft-deprecated and should not be used in new code. Instead see alternatives in quasi_label. |
label, expected.label |
Used to customise failure messages. For expert use only. |
expect_setequal()/expect_mapequal() to test for set equality.
expect_reference() to test if two names point to same memory address.
Other expectations:
comparison-expectations,
expect_error(),
expect_length(),
expect_match(),
expect_named(),
expect_null(),
expect_output(),
expect_reference(),
expect_silent(),
inheritance-expectations,
logical-expectations
a <- 10
expect_equal(a, 10)
# Use expect_equal() when testing for numeric equality
## Not run:
expect_identical(sqrt(2) ^ 2, 2)
## End(Not run)
expect_equal(sqrt(2) ^ 2, 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.