testthat icon indicating copy to clipboard operation
testthat copied to clipboard

expect_equals sometimes reports incorrect values when values are not equal

Open JimMcL opened this issue 1 year ago • 2 comments

The values reported by expect_equal for actual and expected in the case of a test failure are occasionally rounded in incorrect/inconsistent ways. It appears to be an edge case activated by 0.5 values. Example:

> expect_equal(c(8.5, 9.5), c(1.5, 2.5))
Error: c(8.5, 9.5) (`actual`) not equal to c(1.5, 2.5) (`expected`).

  `actual`: 8 10
`expected`: 2  2

Note the reported values for actual and expected.

JimMcL avatar May 07 '24 03:05 JimMcL

Unless there is a desire to keep the formatting as it is, I would be happy to try and address this by refactoring the sprintf formatting?

HHayman avatar Jun 07 '24 10:06 HHayman

This is fixed in the dev version of waldo (which I plan to release to CRAN soon). Now you'll see:

  `actual`: 8.5 9.5
`expected`: 1.5 2.5

I'll leave this issue open as a reminder to myself to bump the required waldo version in testthat.

hadley avatar Oct 22 '24 22:10 hadley