Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In Groovy, can't use == to compare OmniDivisibleValue or large OmniIndivisibleValue #109

Closed
msgilligan opened this issue Sep 28, 2015 · 6 comments
Assignees

Comments

@msgilligan
Copy link
Member

Due to a bug in Groovy, unknown subclasses of Number are converted to Integer before numerical comparison with ==. Thus the following fails:

assert OmniDivisibleValue.of(0.1) == OmniDivisibleValue.of(0.1)   // Fails!

and this does not fail:

assert OmniDivisibleValue.of(1.1) == OmniDivisibleValue.of(1.0)  // Does not fail!

I've reported this to Apache Groovy via JIRA as GROOVY-7608 .

@msgilligan
Copy link
Member Author

@dexX7 Looks like we'll have to use .equals(), like this:

then:
mscBalance.balance.equals(faucetMSC)
mscBalance.reserved.equals(0.divisible)

Until we can get a fixed version of Groovy. It definitely reduces the "Joy of Spock".

@msgilligan
Copy link
Member Author

Wow, looks like there is a PR for this in Groovy: apache/groovy#151

@tkruse
Copy link

tkruse commented May 18, 2016

That's what Pascal said in the JIRA issue 7608. Did you try my PR; and confirmed it fixes both your testcases?
You might also want to read (and maybe reply to) the original thread: http://mail-archives.apache.org/mod_mbox/groovy-dev/201509.mbox/thread ("usage of NumberAwareComparator in extension methods and number oddities (a bit code review) ")

@msgilligan
Copy link
Member Author

Thanks, @tkruse I'll give it a try soon.

@msgilligan msgilligan self-assigned this May 18, 2016
@msgilligan
Copy link
Member Author

Groovy 7608 is fixed and I've verified that it fixes the issue in OmniJ. The fix is scheduled to be in Groovy 2.5.0-beta1.

Sorry @tkruse for not being able to test earlier.

@msgilligan
Copy link
Member Author

As of ad3a7cc we have Groovy 2.5.0-beta-1 on the master branch.

It's probably too soon to start removing the work-arounds, because I'd like to be able to easily fallback to Groovy 2.4.x if we notice any issues. Once we're confident that Groovy 2.5.0-xxx is stable enough we can start removing some of the work-arounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants