Java assert double is Nan
•
Java
I try to assert that my double is Nan
private Double calculateIt(String input){...} assertEquals(Double.NaN,calculateIt("input text"));
The code is not compiled, double Nan is defined as original
public static final double NaN = 0.0d / 0.0;
To make assertions work, I wrap Nan with a Na object
assertEquals(new Double(Double.NaN),calculateIt("input text"));
Is there a shorter way to do this?
Solution
You can use:
boolean isNan = Double.isNaN(calculateIt("input text")); assertTrue(isNan);
Double. The Nan value cannot be compared with = = (double. Nan = = double. Nan will return false) because Nan is considered a special value
More information:
> IEEE floating point
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码