-
Notifications
You must be signed in to change notification settings - Fork 115
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 assertion for floating point number format #789
Comments
Hi, thanks for feedback. Just a clarification question, to what categories would you put |
Thanks for the question! It made me a realise that my suggestions for the method names aren't precise enough. Both I basically want to know whether the number is provided in a floating point syntax. I saw two possible points of confusion that I wanted to avoid in the name:
Therefore, I focussed on the fractional part in the names but forgot about the exponential "e" notation. So for clarity, my updated propositions are |
Cool, if the AssertJ team decides they don't want to add it, I can do it on JsonUnit side |
Read the documentation, maybe we already have the feature
There's a section about numerical comparisons, but I don't need to compare numbers, I need to determine the type.
There's a section about type placeholders, but it only mentions asserting the number type without distinguishing numbers with or without fractional part.
Is your feature request related to a problem? Please describe.
I need to assert that a number has a fractional part, e.g. 653.401 or even 12.0, but not 12.
Describe the solution you'd like
There's already
JsonAssert#isIntegralNumber
, but there's no negated counterpart. So one idea would be to addJsonAssert#isNotIntegralNumber
.This has the downside that the name leaves room for the interpretation that non-numbers like strings would also pass the assertion. To mitigate that, one could pick a name like
isNumberWithFractionalPart
. But thenisIntegralNumber
would have to be renamed toisNumberWithoutFractionalPart
accordingly.I'd find it even more intuitive to write
JsonAssertions.assertThatJson("1.0").isNumber().hasFractionalPart()
and.doesNotHaveFractionalPart()
accordingly, but this would have to be added to AssertJ'sBigDecimalAssert
.Describe alternatives you've considered
I first used
.isNumber().scale().isNotZero()
as workaround, but the failure message is confusing because it refers to the scale, not the checked number. AddingwithFailMessage
isn't that useful as it doesn't allow printing the checked number.Now I'm using
.isNumber().has(new Condition<>(bd -> bd.scale() != 0, "a fractional part"))
and that's fine for now, but I think users shouldn't be forced to write an own solution when the negated assertion is already available.The text was updated successfully, but these errors were encountered: