Java icon indicating copy to clipboard operation
Java copied to clipboard

[BUG] MiniMaxAlgorithm.java file

Open yashsaha555 opened this issue 1 year ago • 2 comments

Description

Found multiple bugs in MiniMaxAlgorithm.java that need to be fixed:

Bugs Identified:

  1. Critical Logic Error in setScores method:

    • Line 114: scores.length % 1 == 0 always returns true
    • Should check if length is a power of 2: (scores.length & (scores.length - 1)) == 0
  2. Edge Case Handling in log2 method:

    • Doesn't handle edge cases like n=0, negative numbers
    • Can cause infinite recursion or incorrect results
  3. Missing Test Coverage:

    • No test file exists for this algorithm
    • Need comprehensive unit tests to prevent regressions

Proposed Solution:

  • Fix the power-of-2 validation logic
  • Add proper edge case handling in log2 method
  • Create comprehensive test suite covering all methods and edge cases
  • Add input validation for boundary conditions

I'd like to work on this issue for Hacktoberfest 2025.

Excepted behavior

  1. setScores method should correctly validate power-of-2 arrays:

    • Should accept arrays with lengths that are powers of 2 (1, 2, 4, 8, 16, etc.)
    • Should reject arrays with lengths that are NOT powers of 2 (3, 5, 6, 7, 9, etc.)
    • Should properly update the internal scores and height when valid input is provided
  2. log2 method should handle all inputs safely:

    • Should correctly calculate log base 2 for valid power-of-2 inputs
    • Should throw meaningful exceptions for invalid inputs (zero, negative numbers, non-power-of-2)
    • Should not cause infinite recursion or stack overflow
  3. Algorithm should have comprehensive test coverage:

    • All public methods should be tested
    • Edge cases and error conditions should be covered
    • Tests should verify the minimax algorithm logic works correctly
    • Tests should prevent future regressions

Screenshots

Image Image

yashsaha555 avatar Oct 01 '25 05:10 yashsaha555

Hi! I’d like to work on this issue for Hacktoberfest 2025. Please assign it to me.

KhushiAgarwal0406 avatar Oct 01 '25 12:10 KhushiAgarwal0406

Hi! šŸ‘‹ I’d like to work on this issue for Hacktoberfest 2025. Could you please assign it to me?

Thanks! šŸ™Œ

Abhinav-1409 avatar Oct 01 '25 14:10 Abhinav-1409