|
RE: assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN: msg#00154java.junit.user
> -----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> |
|---|---|---|
| Previous by Date: | assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN, Morten Grum, PH-Consult |
|---|---|
| Next by Date: | Error on Junit install, Sarah Barwig |
| Previous by Thread: | Re: assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN, kentlbeck |
| Next by Thread: | RE: assertEquals("NaN", x, y, 0.0) where x=y=Double.NaN, Morten Grum, PH-Consult |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |