Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
1.5.1
-
None
-
None
-
WinXP Pro, Java 6 Update 3, Groovy 1.5.1
Description
CODE
---------
def result = (-3).plus(2)
println 'Expected: -1'
println "Actual: ${result}"
println ''
assert ( (-3).plus(2) == -1 )
println 'Passed proper check'
println ''
result = -3.plus(2)
println 'Expected: -1'
println "Actual: ${result}"
println ''
assert ( -3.plus(2) == -5 )
println 'Passed improper check'
println ''
assert ( -3.plus(2) == -1 )
println 'Passed 2nd proper check'
RESULTS
--------------
Expected: -1
Actual: -1
Passed proper check
Expected: -1
Actual: -5
Passed improper check
Caught: java.lang.AssertionError: Expression: (3.plus(2) == -1)
at math.run(math.groovy:19)
at math.main(math.groovy)
=========================
Groovy's parser detects that a number is negative, even if it is not surrounded by parentheses. However, it does not accurate perform the mathematical calculation necessary. Also, the AssertionError message drops the negative sign when it reports a failed assertion if the literal is not surrounded by parentheses.