logo       

RE: assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN: msg#00154

java.junit.user

Subject: RE: assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN



> -----Original Message-----
> From: Morten Grum, PH-Consult [mailto:mg@xxxxxx]
...
> Hi
>
> x and y are both simple double.
>
> Oughtn't assertEquals("x and y", x, y, 0.0) succeed when both
> x and y are
> Double.NaN?
>
> At the moment I'm having to make a situation specific assert
> statement when
> I expect y is Double.NaN.
>
> I'm having to write ...
> assertTrue("When y is NaN", Double.isNaN(y));
>
> I know java returns false on (Double.NaN==y) even when y is
> Double.NaN, but
> for our assert statements I'd say it'd be more practical/general if
> assertEquals succeeded when both were NaN.
>
...
They are correct, in that f0(x)=(5.0-x)/(5.0-x) and
f1(x)=(5.0-x)*(5.0-x)/(5.0-x) are not equal for
x = 5.O, and both are indeterminated (NaN). If you would change
assertEquals(double, double, double)
errors could be introduced for other users.

Why not introduce a method (in an abstract super class perhaps); tailored to
your specific needs ?
assertEqualsNaN(double x, double y, double delta){
if(Double.isNaN(x) && Double.isNaN(y)){
assertTrue(true);
}else{
assertEquals(x, y, delta);
}
}



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise