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
-= Mat
--
Mat Gessel
http://www.asquare.net
> 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.
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