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 tests for collection args with ranges. #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

cmnbroad
Copy link
Collaborator

Just noticed we don't have any tests for collections with ranges, but we should.

@cmnbroad cmnbroad changed the title Add tests for bounded collection args. Add tests for collection args with ranges. Feb 27, 2017
@codecov-io
Copy link

codecov-io commented Feb 27, 2017

Codecov Report

Merging #44 into master will increase coverage by 0.38%.
The diff coverage is 69.04%.

@@             Coverage Diff              @@
##             master      #44      +/-   ##
============================================
+ Coverage     71.36%   71.75%   +0.38%     
+ Complexity      504      498       -6     
============================================
  Files            21       21              
  Lines          2050     2064      +14     
  Branches        425      427       +2     
============================================
+ Hits           1463     1481      +18     
+ Misses          407      404       -3     
+ Partials        180      179       -1
Impacted Files Coverage Δ Complexity Δ
...e/barclay/argparser/CommandLineArgumentParser.java 82.33% <69.04%> (+0.76%) 164 <0> (-6)
...titute/barclay/argparser/CommandLineException.java 55.88% <0%> (+5.88%) 2% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87c3fa2...01a7a8c. Read the comment docs.

Copy link
Contributor

@magicDGS magicDGS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry that I did not add tests for this when I implemented the bounded arguments. I have some suggestion/questions here.

{new String[]{"--intListArg", "-1"}},
{new String[]{"--intListArg", "57"}},
{new String[]{"--intListArg", "1", "--intListArg", "57"}},
{new String[]{"--intListArg", "null" }},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any test for this if the collection does not have bounded arguments? Maybe this corresponds here too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see testClearDefaultValuesFromListArgumentAndAddNew.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is illegal to provide null always? I mean, if the intListArg in this case does not have boundaries, is it forbiden to provide --intListArg null (without any other argument)? And the same case for any other object collection....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If there is no range specified, its perfectly legal to use null to reset the collection (as long as there are no other arguments). But I think you're right that there is no positive test for this, only the negative test to verify that you can't provide other values along with null. I'll add one. At some point I really want to refactor these tests since its really hard to tell whats covered and whats not.

}

@Test(dataProvider = "goodBoundedCollectionArgs")
public void testGoodBoundedCollections(final String[] argv, final Integer[] expectedIntegers) throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why expectedIntegers is not int[]?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only because Integer is the type of the value in the argument, so it makes the Assert overload unambiguous. I did remove the unnecessary .getInt calls from the Asserts though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand it now.

optional = true,
minValue = 0, maxValue = 30,
minRecommendedValue = 10, maxRecommendedValue = 15)
public List<Integer> intListArg = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen if the default list includes a value out of range? It will blow up? Maybe that also requires a test...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what will happen if there are default values and --intListArg null --intListArg 15 to clean the defaults?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first one, there is neither tests nor code to check that the initial value is within range. I added code that throws an internal exception if the initial value is out of range, for both scalar and collection, and tests.

The second one is already illegal. Since the default behavior of this parser for collections is "replace" rather than "append", the parser already enforces that if you pass "null" as a value for a collection, you cannot pass any other values for that arg. If you want to reset the list to a single value of 15, then you just say "--intListArg 15." Finally, I believe we already have a test to validate that "null" is not a valid value for something with a range (since null is always outside the range); I added an additional test to verify that for collections as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot that now is replace instead of append. Thanks for remind me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks for the check of the initial value out of the range.

public void testResetListToNull() {
class ResetListToNull {
@Argument
public List<String> LIST = makeList("foo", "bar");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use instead a numeric list to check that this is correct. That was one of my bugs (see #41) and maybe it is better to be sure that it is not broken also for collections.

Copy link

@LeeTL1220 LeeTL1220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmnbroad Minor comments.

|| !isInfinityOrMathematicalInteger(this.minValue)
|| !isInfinityOrMathematicalInteger(this.maxRecommendedValue)
|| !isInfinityOrMathematicalInteger(this.minRecommendedValue)) {
throw new CommandLineException.CommandLineParserInternalException(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the maximum (or minimum) value be infinity? If so, this will fail. I agree that users should not specify these values, but perhaps this error message should include the suggestion not to specify infinity.

public void testBoundedCollectionIntializedOutOfRange() throws Exception {
@CommandLineProgramProperties(
summary = "tool with bounded collection argument with bad initial value",
oneLineSummary = "ool with bounded collection argument with bad initial value",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

// Check recommended values
if (hasRecommendedRange() && isOutOfRange(minRecommendedValue, maxRecommendedValue, argumentDoubleValue)) {
final boolean outMinValue = minRecommendedValue != Double.NEGATIVE_INFINITY;
final boolean outMaxValue = maxRecommendedValue != Double.POSITIVE_INFINITY;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check for NaN? This may be a matter of opinion...

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.

4 participants