-
Notifications
You must be signed in to change notification settings - Fork 18.8k
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
Refactor: Combination #5225
base: master
Are you sure you want to change the base?
Refactor: Combination #5225
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5225 +/- ##
============================================
- Coverage 39.22% 39.20% -0.02%
+ Complexity 2401 2400 -1
============================================
Files 517 517
Lines 15522 15517 -5
Branches 2958 2957 -1
============================================
- Hits 6089 6084 -5
Misses 9140 9140
Partials 293 293 ☔ View full report in Codecov by Sentry. |
assert result != null; | ||
assertEquals(1, (int) result.get(0).getFirst()); | ||
assertEquals(2, (int) result.get(1).getFirst()); |
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.
assert result != null; | |
assertEquals(1, (int) result.get(0).getFirst()); | |
assertEquals(2, (int) result.get(1).getFirst()); | |
assertEquals(Arrays.asList(new TreeSet<>(Arrays.asList(1)), new TreeSet<>(Arrays.asList(2))), result); |
assert result != null; | ||
Integer[] arr = result.getFirst().toArray(new Integer[2]); | ||
assertEquals(1, (int) arr[0]); | ||
assertEquals(2, (int) arr[1]); |
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.
assert result != null; | |
Integer[] arr = result.getFirst().toArray(new Integer[2]); | |
assertEquals(1, (int) arr[0]); | |
assertEquals(2, (int) arr[1]); | |
assertEquals(Arrays.asList(new TreeSet<>(Arrays.asList(1, 2))), result); |
} else if (combinationSize == 0) { | ||
return null; | ||
} |
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.
I do not see a reason to return null
here. You can just remove this branch, so the result would be Arrays.asList(new TreeSet<Integer>())
.
The problem is ArrayCombination
. The method combination
will need an update.
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.
Could you please:
- add a test case with
data
being an empty array andcombinationSize
being positive, - add a test case with
data
being an empty array andcombinationSize
being zero, - add a test case with
data
being[1, 2, 3]
andcombinationSize
being2
, - add a test case with data being an array of strings.
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
/** | ||
* Finds all permutations of given array | ||
* @author Alan Piao (<a href="https://github.com/cpiao3">git-Alan Piao</a>) | ||
* Finds all combinations of a given array of unique elements. |
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.
This is not verified anywhere. Maybe the input type should be Set<T>
? Or maybe this statement is not needed. I think what we are aiming for it to mimic the itertools.combinations
from python.
Related to #5164
clang-format -i --style=file path/to/your/file.java