Skip to content

Fix AbsoluteMin comparison by absolute magnitude#7540

Draft
kush2439p wants to merge 2 commits into
TheAlgorithms:masterfrom
kush2439p:agent/fix-absolute-min-magnitude
Draft

Fix AbsoluteMin comparison by absolute magnitude#7540
kush2439p wants to merge 2 commits into
TheAlgorithms:masterfrom
kush2439p:agent/fix-absolute-min-magnitude

Conversation

@kush2439p

Copy link
Copy Markdown

Summary

  • compare candidates by absolute magnitude and return the original signed value
  • preserve the existing deterministic tie behavior by choosing the numerically smaller value
  • add coverage for mixed signs, both-negative, both-positive, equal magnitudes, and zero

Root cause

AbsoluteMin.getMinValue filtered candidates using their absolute values, but then updated the result with Math.min on the raw signed values. A larger-magnitude negative number could therefore replace the correct candidate.

Validation

  • javac compilation and direct behavior checks passed
  • git diff --check passed
  • mvn -Dtest=AbsoluteMinTest test reached test compilation, but the upstream checkout has unrelated missing-class compilation failures across existing tests before Surefire can select the focused test

Fixes #7537

@kush2439p
kush2439p force-pushed the agent/fix-absolute-min-magnitude branch from 7c1b1ed to ecf7664 Compare July 23, 2026 07:17
@kush2439p

Copy link
Copy Markdown
Author

This PR corrects AbsoluteMin.getMinValue to compare values by absolute magnitude while returning the original signed value.
It also documents deterministic tie handling (the numerically smaller value is chosen) and adds tests for mixed signs, negative values, positive values, ties, and zero.
Validation:
Checkstyle passed
Direct behavior checks passed
Full Maven test compilation is currently blocked by unrelated missing classes in the upstream checkout.

@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.31%. Comparing base (8a20fa9) to head (c53c00b).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7540      +/-   ##
============================================
- Coverage     80.32%   80.31%   -0.01%     
- Complexity     7402     7404       +2     
============================================
  Files           812      812              
  Lines         23911    23915       +4     
  Branches       4704     4706       +2     
============================================
+ Hits          19206    19208       +2     
- Misses         3944     3945       +1     
- Partials        761      762       +1     

☔ View full report in Codecov by Harness.
📢 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.

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] <title>

2 participants