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
expect_that(sqrt(2) ^ 2 == 2, is_true())
expect_that(sqrt(2) ^ 2, is_identical_to(2))
# You can pass on additional arguments to all.equal:
# 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)
Run the code above in your browser using DataLab