I want to test that two values are not equal using 'testthat'. I can test equality using something like
expect_that(x, equals(y))
But, what if I expect them to not be equal? I could use
expect_false(x == y)
Is this the right way to do it or is there something like
expect_that(x, not_equals(y))
The function testthat::equals()
is really a wrapper around all.equal
. So you can construct your test like this:
x <- 1:5
y <- 2:6
expect_false(isTRUE(all.equal(x, y)))
expect_false(isTRUE(all.equal(x+1, y)))
Error: isTRUE(all.equal(x + 1, y)) isn't false
You need to use isTRUE
in there, since all.equal
returns a character string if its arguments aren't equal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With