expect_identical() compares values with identical().
expect_equal() compares values with all.equal()
expect_equivalent() compares values with all.equal() and
check.attributes = FALSE
expect_reference() compares the underlying memory addresses.
expect_equal( object, expected, ..., info = NULL, label = NULL, expected.label = NULL ) expect_equivalent( object, expected, ..., info = NULL, label = NULL, expected.label = NULL ) expect_identical( object, expected, info = NULL, label = NULL, expected.label = NULL, ... ) expect_reference( 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. |
|---|---|
| ... | For |
| 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() to test for set equality.
Other expectations:
comparison-expectations,
expect_error(),
expect_length(),
expect_match(),
expect_message(),
expect_named(),
expect_null(),
expect_output(),
expect_silent(),
inheritance-expectations,
logical-expectations
#> [1] 1expect_equal(sqrt(2) ^ 2, 2) # Neither of these forms take floating point representation errors into # account if (FALSE) { expect_true(sqrt(2) ^ 2 == 2) expect_identical(sqrt(2) ^ 2, 2) } # You can pass on additional arguments to all.equal: if (FALSE) { # Test the ABSOLUTE difference is within .002 expect_equal(10.01, 10, tolerance = .002, scale = 1) } # Test the RELATIVE difference is within .002 x <- 10 expect_equal(10.01, expected = x, tolerance = 0.002, scale = x) # expect_equivalent ignores attributes a <- b <- 1:3 names(b) <- letters[1:3] expect_equivalent(a, b)