JUnit and float values

15 views
Skip to first unread message

Mat Gessel

unread,
Aug 14, 2006, 3:54:28 PM8/14/06
to GWT Group
This bug still exists in 1.1:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/d4decb1467b2b202/c54c8370d583e023

Consider passing the following values to assertEquals:
0.0, 0.0, 0.0 (false failure)
1.0, 2.0, 0.1 (false pass)
-1.0, -2.0, 0.1 (false pass)

Assert super-source:

static public void assertEquals(String str, float obj1, float obj2,
float delta) {
if (obj1 - obj2 < delta || obj2 - obj1 < delta) {
return;
} else {
fail(str + " expected=" + obj1 + " actual=" + obj2 + " delta=" + delta);
}
}

I suggested a better implementation in the linked post.

--
Mat Gessel
http://www.asquare.net

Scott Blum

unread,
Aug 14, 2006, 7:07:36 PM8/14/06
to Google Web Toolkit
Wish I hadn't missed the thread you linked! Good catch.

--Scott

Mat Gessel

unread,
Aug 15, 2006, 3:15:58 PM8/15/06
to Google-We...@googlegroups.com
The fix I previously suggested was flawed as well. A corrected version
is attached, along with a test case.

-= Mat

JUnitTC.java
Assert.java

Konstantin Scheglov

unread,
Aug 15, 2006, 3:20:38 PM8/15/06
to Google Web Toolkit

Scott Blum wrote:

> Wish I hadn't missed the thread you linked! Good catch.

Setup public Bugzilla and you will not lost bug reports from users.

In Eclipse newsgroups developers always tell us, users - don't post
bug reports in newsgroup, we can just forget about them, post them in
bugzilla and we will find them.

Scott Blum

unread,
Aug 15, 2006, 3:32:49 PM8/15/06
to Google Web Toolkit
Nice work, Mat.

I'm incorporating your test case into an existing on. Your fix looks
good except I think that should be a "<= delta" instead of a "< delta".

This is the code I think I'm going to commit:

static public void assertEquals(String str, double obj1, double obj2,
double delta) {
if (obj1 == obj2) {
return;
} else if (Math.abs(obj1 - obj2) <= delta) {


return;
} else {
fail(str + " expected=" + obj1 + " actual=" + obj2 + " delta=" +
delta);
}
}

static public void assertEquals(String str, float obj1, float obj2,
float delta) {
if (obj1 == obj2) {
return;
} else if (Math.abs(obj1 - obj2) <= delta) {


return;
} else {
fail(str + " expected=" + obj1 + " actual=" + obj2 + " delta=" +
delta);
}
}

--Scott

Reply all
Reply to author
Forward
0 new messages