thanneeruvenu / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

closeTo() for Double gives different results than Double.compare() #262

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? If possible, provide source code and
stack trace.

def "test"() {
expect:
//gives true:
assert Double.compare(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY) == 0

//fails:
that Double.POSITIVE_INFINITY, closeTo(Double.POSITIVE_INFINITY, 0.1d)
}

What version of Spock and Groovy are you using?
Spock-0.6, Groovy 1.8

Please provide any additional information below. You can also assign
labels.
spock.util.matcher.HamcrestMatchers.closeTo() uses minus to calculate delta, 
but Double.compare() compares bits for the same values. So, IMHO the correct 
impl would be something like:
if (compare() == 0) { return true; } return isWithinDelta();

Original issue reported on code.google.com by cum...@gmail.com on 1 Aug 2012 at 12:47

GoogleCodeExporter commented 8 years ago
Good catch, and thanks for reporting.

Original comment by pnied...@gmail.com on 26 Aug 2012 at 7:15