Skip to content

Add equivalence tests for capMissingBytes old vs new formula#23

Merged
bernardladenthin merged 2 commits intomasterfrom
claude/fix-read-conditional-mutation-vrhkH
Apr 8, 2026
Merged

Add equivalence tests for capMissingBytes old vs new formula#23
bernardladenthin merged 2 commits intomasterfrom
claude/fix-read-conditional-mutation-vrhkH

Conversation

@bernardladenthin
Copy link
Copy Markdown
Owner

Summary

This PR adds comprehensive test coverage to verify that the new capMissingBytes formula (using unconditional Math.min) produces identical results to the previous conditional formula across all edge cases.

Key Changes

  • Added two helper methods that extract the old and new capMissingBytes formulas for direct comparison:
    • capMissingBytesOld(): The original guarded if-block formula (pre-cb66b68)
    • capMissingBytesNew(): The new unconditional Math.min formula (post-cb66b68)
  • Created a comprehensive @DataProvider with 11 test cases covering three scenarios:
    • Case A: maxAvail < missingBytes (old if-branch executes, new Math.min picks maxAvail)
    • Case B: maxAvail == missingBytes (boundary condition at equality)
    • Case C: maxAvail > missingBytes (old skips if, new Math.min picks missingBytes)
  • Added parameterized test capMissingBytes_oldAndNewFormula_returnSameResult() that validates equivalence across all cases, including edge cases like Integer.MAX_VALUE and Long.MAX_VALUE

Notable Implementation Details

  • Test cases include boundary values and extreme cases to ensure the formula refactoring maintains correctness
  • The test uses JUnit's @DataProvider for parameterized testing with clear case categorization
  • All test inputs are designed to exercise different code paths in both formulas to guarantee behavioral equivalence

https://claude.ai/code/session_01HYTj7Mg73S1Le9QTn7XFxu

claude added 2 commits April 8, 2026 20:14
Adds two private static helper methods to StreamBufferTest that extract
the old (if-guarded) and new (unconditional Math.min) capping formulas
verbatim, plus a @dataProvider with 10 input rows covering all three
equivalence classes:

  A: maximumAvailableBytes < missingBytes  (old if-branch fires)
  B: maximumAvailableBytes == missingBytes (boundary)
  C: maximumAvailableBytes > missingBytes  (old if skipped, incl. > INT_MAX)

The parameterised test capMissingBytes_oldAndNewFormula_returnSameResult
asserts that both formulas produce identical int results for every row,
proving the commit cb66b68 refactor is semantically correct.

https://claude.ai/code/session_01HYTj7Mg73S1Le9QTn7XFxu
Old URLs used /repos/<owner>/ and /r/<owner>/ paths which are legacy.
Updated to /repos/github/<owner>/ and /github/<owner>/ as required
by the current Coveralls API.

https://claude.ai/code/session_01HYTj7Mg73S1Le9QTn7XFxu
@bernardladenthin bernardladenthin merged commit 5829085 into master Apr 8, 2026
6 checks passed
@bernardladenthin bernardladenthin deleted the claude/fix-read-conditional-mutation-vrhkH branch April 8, 2026 20:39
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.

2 participants