Skip to content

fix: reject negative input in SumOfSquares#7539

Draft
oozan wants to merge 3 commits into
TheAlgorithms:masterfrom
oozan:fix-sum-of-squares-negative-input-1784733818
Draft

fix: reject negative input in SumOfSquares#7539
oozan wants to merge 3 commits into
TheAlgorithms:masterfrom
oozan:fix-sum-of-squares-negative-input-1784733818

Conversation

@oozan

@oozan oozan commented Jul 22, 2026

Copy link
Copy Markdown

Description

Rejects negative inputs in SumOfSquares instead of returning the mathematically incorrect result 3.

The public method now throws IllegalArgumentException with a clear message, and its Javadoc documents the behavior.

Testing

  • Added a regression test for negative input
  • Compiled the implementation directly with javac
  • Verified the existing one-, two-, three-, and four-square cases
  • Verified that negative input throws IllegalArgumentException

Closes #7538

Checklist

  • Filenames use PascalCase
  • Java naming conventions are followed
  • The existing algorithm documentation link is preserved
  • The behavior is covered by a corresponding test
  • The change follows the existing formatting style

AI assistance was used to prepare this focused fix. I reviewed and validated the implementation.

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] SumOfSquares accepts negative input

1 participant