| equivalence {testthat} | R Documentation |
expect_identical tests with identical
expect_equal tests with all.equal
expect_equivalent tests with all.equal and
check.attributes = FALSE
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)
object |
object to test |
expected |
Expected value |
... |
other values passed to |
info |
extra information to be included in the message (useful when writing tests in loops). |
label |
For full form, label of expected object used in error
messages. Useful to override default (deparsed expected expression) when
doing tests in a loop. For short cut form, object label. When
|
expected.label |
Equivalent of |
Other expectations: expect-compare,
expect_gt, expect_gte,
expect_less_than, expect_lt,
expect_lte, expect_more_than;
expect_equal_to_reference;
expect_error, expect_match,
expect_message,
expect_output,
expect_warning,
matching-expectations;
expect_false, expect_true;
expect_is; expect_named;
expect_null; expect_silent;
takes_less_than
a <- 10 expect_equal(a, 10) # Use equals() when testing for numeric equality sqrt(2) ^ 2 - 1 expect_equal(sqrt(2) ^ 2, 2) # Neither of these forms take floating point representation errors into # account ## Not run: expect_true(sqrt(2) ^ 2 == 2) expect_identical(sqrt(2) ^ 2, 2) ## End(Not run) # You can pass on additional arguments to all.equal: ## Not run: # Test the ABSOLUTE difference is within .002 expect_equal(object = 10.01, expected = 10, tolerance = .002, scale = 1) # Test the RELATIVE difference is within .002 expectedValue <- 10 expect_equal(object = 10.01, expected = expectedValue, tolerance = 0.002, scale = expectedValue) ## End(Not run) # expect_equivalent ignores attributes a <- b <- 1:3 names(b) <- letters[1:3] expect_equivalent(a, b)