Skip to content

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

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/java/org/junit/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ static public void fail() {
*/
static public void assertEquals(String message, Object expected,
Object actual) {
if (equalsRegardingNull(expected, actual)) {
if (expected instanceof Double && actual instanceof Double) {
assertEquals(message, (Double) expected, (Double) actual, 0.0);
} else if (expected instanceof Float && actual instanceof Float) {
assertEquals(message, (Float) expected, (Float) actual, 0.0);
} else if (equalsRegardingNull(expected, actual)) {
return;
} else if (expected instanceof String && actual instanceof String) {
String cleanMessage = message == null ? "" : message;
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/org/junit/tests/assertion/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ public void equals() {
assertEquals(1l, 1l);
assertEquals(1.0, 1.0, 0.0);
assertEquals(1.0d, 1.0d, 0.0d);
assertEquals(new Double(0.0), new Double(-0.0), 0.0d);
assertEquals(new Double(0.0), new Double(-0.0));
assertEquals(new Float(0.0), new Float(-0.0), 0.0);
assertEquals(new Float(0.0), new Float(-0.0));
}

@Test(expected = AssertionError.class)
Expand Down