I was wondering why assertEquals(double, double)
is deprecated.
I used import static org.junit.Assert.assertEquals;
and I used JUnit 4.11.<
It's deprecated because of the double's precision problems.
If you note, there's another method assertEquals(double expected, double actual, double delta)
which allows a delta
precision loss.
JavaDoc:
Asserts that two doubles are equal to within a positive delta. If they are not, an AssertionError is thrown. If the expected value is infinity then the delta value is ignored.NaNs are considered equal:
assertEquals(Double.NaN, Double.NaN, *)
passes...
delta - the maximum delta between expected and actual for which both numbers are still considered equal.