Skip to content

Conversation

yashsaha555
Copy link

@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

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 75.36%. Comparing base (421ac6d) to head (9e45058).

Files with missing lines Patch % Lines
...ava/com/thealgorithms/others/MiniMaxAlgorithm.java 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6566      +/-   ##
============================================
+ Coverage     75.19%   75.36%   +0.16%     
- Complexity     5614     5634      +20     
============================================
  Files           690      690              
  Lines         19407    19409       +2     
  Branches       3755     3755              
============================================
+ Hits          14593    14627      +34     
+ Misses         4247     4212      -35     
- Partials        567      570       +3     

☔ 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
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
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