Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expect_not_equal in pkg:testthat

Tags:

r

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))
like image 246
adamleerich Avatar asked Aug 24 '12 14:08

adamleerich


1 Answers

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.

like image 135
Andrie Avatar answered Oct 17 '22 15:10

Andrie