Skip to content

Conversation

@quincy
Copy link

@quincy quincy commented Sep 17, 2014

If you compare 0.0 and -0.0 with assertEquals you get different answers depending on whether you pass a delta value of 0.0. I would expect them to give the same answer. This patch contains a fix for assertEquals and a change to the unit test to verify correctness.

@marcphilipp
Copy link
Member

In my point of view the current implementation is correct.

assertEquals(Object, Object) checks for object equivalence as specified by java.lang.Object.equals(Object). Since new Double(0.0d).equals(new Double(-0.0d)) returns false, assertEquals(new Double(0.0d), new Double(-0.0d)) must fail.

That said, comparing doubles that way should be avoided. For this very reason assertEquals(double, double) is deprecated and will even throw an assertion error.

@kcooney
Copy link
Member

kcooney commented Sep 17, 2014

I agree with Marc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants