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

Add BigDecimal edge case for equals vs compareTo discrepancy #2403

Merged
merged 1 commit into from
Aug 17, 2021

Conversation

dchenbecker
Copy link
Contributor

BigDecimal is not consistent for equals and compareTo when the
scale differs. This adds an edge case using the String constructor for
BigDecimal to force a different scale.

@dchenbecker
Copy link
Contributor Author

I'm looking for some guidance about how to best unit test this. My expectation is that with a proper seed I could get a 2-ary function to get both edge cases, but I'm not sure how simple that is, or if there's another approach to take here.

@sksamuel
Copy link
Member

sksamuel commented Aug 5, 2021

You could just call the edge cases method multiple times and assert you get both of the 0.0 and 0.00 in the output.

@sksamuel
Copy link
Member

sksamuel commented Aug 13, 2021

Something like Arb.bigDecimal().edgecases().contains(BigDecimal("0.00")) ought to do it.

@dchenbecker dchenbecker force-pushed the add-bigdecimal-edgecase branch from c13f493 to e82af64 Compare August 17, 2021 16:38
BigDecimal is not consistent for equals and compareTo when the
scale differs. This adds an edge case using the String constructor for
BigDecimal to force a different scale.
@dchenbecker dchenbecker force-pushed the add-bigdecimal-edgecase branch from e82af64 to 4e01bac Compare August 17, 2021 18:30
@sksamuel sksamuel merged commit 985bdda into kotest:master Aug 17, 2021
@sksamuel
Copy link
Member

👍🏼

@sksamuel sksamuel modified the milestones: 5.0, 4.6.2 Aug 17, 2021
sksamuel pushed a commit that referenced this pull request Aug 24, 2021
BigDecimal is not consistent for equals and compareTo when the
scale differs. This adds an edge case using the String constructor for
BigDecimal to force a different scale.
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

Successfully merging this pull request may close these issues.

2 participants