Skip to content

Conversation

yashsaha555
Copy link
Contributor

@yashsaha555 yashsaha555 commented Oct 1, 2025

  • Fix bug in setScores method where scores.length % 1 == 0 always returned true
  • Add isPowerOfTwo helper method to properly validate array length
  • Add comprehensive unit tests covering edge cases and algorithm correctness
  • Tests include validation for power of 2 check, minimax logic, and error handling

Issue

Fixes #6563

Fixes issue with incorrect validation logic in MiniMaxAlgorithm.setScores()

  • 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

- Fix bug in setScores method where scores.length % 1 == 0 always returned true
- Add isPowerOfTwo helper method to properly validate array length
- Add comprehensive unit tests covering edge cases and algorithm correctness
- Tests include validation for power of 2 check, minimax logic, and error handling

Fixes issue with incorrect validation logic in MiniMaxAlgorithm.setScores()
@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.49%. Comparing base (f8f315e) to head (86e0f4f).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6566      +/-   ##
============================================
+ Coverage     75.31%   75.49%   +0.18%     
- Complexity     5659     5679      +20     
============================================
  Files           693      693              
  Lines         19552    19554       +2     
  Branches       3786     3786              
============================================
+ Hits          14725    14763      +38     
+ Misses         4252     4215      -37     
- Partials        575      576       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

yashsaha555 and others added 4 commits October 1, 2025 12:14
- Replace star imports with explicit imports in test file
- Remove trailing whitespaces from all lines
- Add proper file ending newline
- Improve setScores method to handle edge cases properly
- Use direct bit manipulation for power-of-2 check as suggested
- Ensure error message is printed and scores remain unchanged for invalid input

All Checkstyle violations resolved and tests pass successfully.
- Fix Checkstyle violation: NewlineAtEndOfFile
- Ensure file ends with proper newline character
- All tests continue to pass successfully
- Replace inline bit manipulation with isPowerOfTwo method call
- Resolves PMD UnusedPrivateMethod violation
- Maintains same validation logic and error handling
- All tests continue to pass successfully
DenizAltunkapan
DenizAltunkapan previously approved these changes Oct 1, 2025
Copy link
Member

@DenizAltunkapan DenizAltunkapan left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks

@DenizAltunkapan DenizAltunkapan enabled auto-merge (squash) October 1, 2025 15:25
- Add comprehensive test cases for isPowerOfTwo function edge cases
- Test setScores method with various invalid array lengths (0, 3, 5, 6, 7, 9, 10, 15)
- Add tests for large valid powers of 2 (up to 64 elements)
- Ensure complete coverage of error handling branches
- Increase test count from 14 to 19 tests
- Fix partial coverage issues identified in CodeCov report

Resolves CodeCov coverage gaps in MiniMaxAlgorithm.java
auto-merge was automatically disabled October 1, 2025 19:41

Head branch was pushed to by a user without write access

@yashsaha555
Copy link
Contributor Author

Hi @DenizAltunkapan , could you please re-review my PR? I've added some additional test cases to increase the code coverage.

@DenizAltunkapan DenizAltunkapan enabled auto-merge (squash) October 2, 2025 07:23
@DenizAltunkapan DenizAltunkapan merged commit 15695c6 into TheAlgorithms:master Oct 2, 2025
6 checks passed
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.

[BUG] MiniMaxAlgorithm.java file
4 participants