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

Adds tests for numbers #58

Merged
merged 4 commits into from
Aug 17, 2016
Merged

Adds tests for numbers #58

merged 4 commits into from
Aug 17, 2016

Conversation

johnjaylward
Copy link
Contributor

@johnjaylward johnjaylward commented Aug 16, 2016

This adds positive tests for how numbers are handled and output. It adds in 3 new classes:

  • Fraction: simple fraction class that has a toString() which outputs numbers in a format not compatible with JSON
  • MyNumber: simple number override that expresses the constant 42. This has a valid toString method that outputs numbers in a JSON compatible format
  • MyNumberContainer: a simple bean that holds a MyNumber instance. No toString() method is defined.

These tests show a bug in the way numbers are currently output by the library as no validation is done to ensure that they are the proper format.

See PR stleary/JSON-java#272 on the main library for conversations on fixes. that PR now offers a fix which solve the bug.

John J. Aylward and others added 2 commits August 16, 2016 20:52
@stleary
Copy link
Owner

stleary commented Aug 17, 2016

Thanks, this is a good addition for Number tests, though it can't be accepted while the tests fail.

@johnjaylward
Copy link
Contributor Author

All these tests should pass. The bug is validated as a positive test.

@stleary
Copy link
Owner

stleary commented Aug 17, 2016

I am using JSON-Java latest master branch and JSON-Java-unit-test SimplifyNumberWrap branch. Got an error in JSONObjectTest:
org.json.junit.JSONObjectTest > verifyNumberOutput FAILED
org.junit.ComparisonFailure at JSONObjectTest.java:188

@johnjaylward
Copy link
Contributor Author

ah, I'll retest then. when I tried they all passed.

@johnjaylward
Copy link
Contributor Author

fixed

@stleary
Copy link
Owner

stleary commented Aug 17, 2016

Fails now in line 207 - I think the JSONObject string is ordered differently on my machine than on yours:
actual "{"myNumber":{"numerator":4,"denominator":2}}" (id=45)
expected "{"myNumber":{"denominator":2,"numerator":4}}" (id=50)
Try fixing with JSONPointer :) e.g.

JSONPointer jsonPointer = new JSONPointer("/myNumber/denominator");
assertEquals(BigInteger.valueOf(2), jsonPointer.queryFrom(jsonObject));

@johnjaylward
Copy link
Contributor Author

ah that makes sense, and I knew that when I wrote it, but forgot to fix it
before finalizing it.

On Wed, Aug 17, 2016 at 12:06 PM, Sean Leary notifications@github.com
wrote:

Fails now in line 207 - I think the JSONObject string is ordered
differently on my machine than on yours:
actual "{"myNumber":{"numerator":4,"denominator":2}}" (id=45)

expected "{"myNumber":{"denominator":2,"numerator":4}}" (id=50)

Try fixing with JSONPointer :) e.g.
JSONPointer jsonPointer = new JSONPointer("/myNumber/denominator");
assertEquals(BigInteger.valueOf(2), jsonPointer.queryFrom(jsonObject));


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#58 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAXa12-MWgEKyfM1HDVVJp7ycNG75Faoks5qgzGHgaJpZM4Jl9p5
.

John.

@stleary stleary merged commit 59761f6 into stleary:master Aug 17, 2016
@johnjaylward johnjaylward deleted the SimplifyNumberWrap branch July 10, 2017 14:16
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