-
Notifications
You must be signed in to change notification settings - Fork 87
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
Big decimal range #69
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,13 +77,35 @@ public void randomBigDecimalWithMathContextTest() { | |
assertTrue("Generated value should have a precision of 3", ((BigDecimal) value).precision() == 3); | ||
} | ||
|
||
@Test | ||
public void randomBigDecimalUsingRange() { | ||
RandomFunction random = new RandomFunction(BigDecimal.class, new Range(1, 1000)); | ||
BigDecimal bigDecimal = random.generateValue(); | ||
|
||
assertNotNull("Generated BigDecimal must not be null", bigDecimal); | ||
assertTrue("Generated value must be a BigDecimal", bigDecimal instanceof BigDecimal); | ||
assertTrue(new BigDecimal("1").compareTo(bigDecimal) != 1); | ||
assertTrue(new BigDecimal("1000").compareTo(bigDecimal) != -1); | ||
} | ||
|
||
@Test | ||
public void randomBigIntegerTest() { | ||
Object value = new RandomFunction(BigInteger.class).generateValue(); | ||
assertNotNull("Generated BigInteger must not be null", value); | ||
assertTrue("Generated value is not a BigInteger", value instanceof BigInteger); | ||
} | ||
|
||
@Test | ||
public void randomBigIntegerTestUsingRange() { | ||
RandomFunction random = new RandomFunction(BigInteger.class, new Range(1, 1000)); | ||
BigInteger bigInteger = random.generateValue(); | ||
|
||
assertNotNull("Generated BigInteger must not be null", bigInteger); | ||
assertTrue("Generated value is not a BigInteger", bigInteger instanceof BigInteger); | ||
assertTrue(new BigInteger("1").compareTo(bigInteger) != 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about the range check here. |
||
assertTrue(new BigInteger("1000").compareTo(bigInteger) != -1); | ||
} | ||
|
||
@Test | ||
public void randomBooleanTest() { | ||
Object value = new RandomFunction(Boolean.class).generateValue(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here should be better to check if the generated value is in the range instead of checking if it's not the
limit values
. Something like:What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
Yeah I agree, reading BigDecimal comparison is really annoying. But the problem is that the compareTo method will only return (-1, 0, 1) for less than, equals to, greater than the other value.
But I'll come up with some clever idea to make it a little more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csrcordeiro actually is possible to compare exactly the same as with operators, check the Javadoc here: http://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html#compareTo(java.math.BigDecimal)
You could change your asserts to be like this:
The above code is the same as: