Java — on doubles and equality
•
Java
I have a method that returns a double When I tested this method as part of JUnit, I noticed the following oddities:
String a = "someString"; String b = "someDifferentString"; double result = c.getscore(a,b,true); System.out.println(result); // prints 0.0 assert (result > 0.0); // Test passes
So I ask you, how can 0.0 exceed 0.0? Why is the result > 0.0 evaluated as true?
Solution
Assert is a Java keyword You need asserttrue (result > 0.0)
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
二维码