equals {testthat}R Documentation

Expectation: is the object equal (with numerical tolerance) to a value?

Description

Comparison performed using all.equal.

Usage

  equals(expected, label = NULL, ...)

  expect_equal(object, expected, ..., info = NULL,
    label = NULL, expected.label = NULL)

Arguments

expected

Expected value

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 NULL, computed from deparsed object.

expected.label

Equivalent of label for shortcut form.

...

other values passed to all.equal

object

object to test

info

extra information to be included in the message (useful when writing tests in loops).

See Also

Other expectations: expect_equivalent, expect_error, expect_false, expect_identical, expect_is, expect_match, expect_message, expect_output, expect_true, expect_warning, gives_warning, is_a, is_equivalent_to, is_false, is_identical_to, is_true, matches, prints_text, shows_message, takes_less_than, throws_error

Examples

a <- 10
expect_that(a, equals(10))
expect_equal(a, 10)

# Use equals() when testing for numeric equality
sqrt(2) ^ 2 - 1
expect_that(sqrt(2) ^ 2, equals(2))
expect_equal(sqrt(2) ^ 2, 2)
# Neither of these forms take floating point representation errors into
# account
## Not run: 
expect_that(sqrt(2) ^ 2 == 2, is_true())
expect_that(sqrt(2) ^ 2, is_identical_to(2))

## End(Not run)

[Package testthat version 0.6 Index]