Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertEquals(0.0, -0.0, 0.0) and assertEquals(0.0, -0.0) give different answers #992

Closed
wants to merge 1 commit into from

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