Does code return the expected value?Source:
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,
all.equal(). In the 3rd edition, both functions use
waldo. They differ only in that
tolerance = testthat_tolerance() so that small
floating point differences are ignored; this also implies that (e.g.)
1L are treated as equal.
- 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
waldo::compare(). See its docs to see other ways to control comparison.
3e: passed on to
waldo::compare(). If non-
NULL, will ignore small floating point differences. It uses same algorithm as
all.equal()so the tolerance is usually relative (i.e.
mean(abs(x - y) / mean(abs(y)) < tolerance), except when the differences are very small, when it becomes absolute (i.e.
mean(abs(x - y) < tolerance). See waldo documentation for more details.
2e: passed on to
compare(), if set. It's hard to reason about exactly what tolerance means because depending on the precise code path it could be either an absolute or relative tolerance.
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_reference()to test if two names point to same memory address.