r-lib / testthat

An R 📦 to make testing 😀
https://testthat.r-lib.org
Other
868 stars 313 forks source link

expect_equals sometimes reports incorrect values when values are not equal #1955

Open JimMcL opened 1 month ago

JimMcL commented 1 month ago

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.

HHayman commented 3 weeks ago

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?