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

Refactor: Combination #5225

Closed
wants to merge 13 commits into from

Conversation

samuelfac
Copy link
Contributor

Related to #5164

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Project coverage is 40.32%. Comparing base (8ea90fd) to head (a25969d).

Files Patch % Lines
...va/com/thealgorithms/backtracking/Combination.java 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5225      +/-   ##
============================================
- Coverage     40.35%   40.32%   -0.04%     
+ Complexity     2486     2484       -2     
============================================
  Files           519      519              
  Lines         15479    15474       -5     
  Branches       2950     2949       -1     
============================================
- Hits           6247     6240       -7     
- Misses         8943     8944       +1     
- Partials        289      290       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samuelfac samuelfac marked this pull request as ready for review June 12, 2024 18:10
Comment on lines +27 to 29
} else if (combinationSize == 0) {
return null;
}
Copy link
Member

@vil02 vil02 Jul 4, 2024

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. I force merged #5181, so this null problem will no longer occur.

Copy link
Member

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 and combinationSize being positive,
  • add a test case with data being an empty array and combinationSize being zero,
  • add a test case with data being [1, 2, 3] and combinationSize being 2,
  • 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.
Copy link
Member

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.

samuelfac and others added 2 commits July 11, 2024 11:22
Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

@github-actions github-actions bot added the stale label Aug 11, 2024
Copy link

Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution!

@github-actions github-actions bot closed this Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants