test: exercise adjustExponent logic paths in div#236
Conversation
The `div` implementation selects an `adjustExponent` for scaling the numerator via a binary search over the order of magnitude of the (maximized) divisor coefficient. The smaller-than-1e75 leaves of that search were not exercised by the existing tests, because they are only reachable when the divisor cannot be maximized (its exponent is pinned at type(int256).min, leaving the coefficient at its given magnitude). Adds deterministic unit tests covering: - every interior leaf of the binary search (one divisor strictly inside each sub-range, 1e5 .. 1e75) plus the "noop" leaf, - the strict `<` boundary comparisons at each power-of-ten boundary, - the dedicated full-divisor (scale 1e75) and >=1e76 (scale 1e76) paths, - the exponent-adjustment application paths: applied to exponentA, spilled over onto exponentB, the spill-overflow return-zero case, and the underflow return-zero case. Each case asserts the round-trip identity `(a / b) * b == a` (compared as a value via `eq`), which pins both the quotient mantissa and the `adjustExponent` constant for that branch: a wrong constant scales the quotient by a power of ten and breaks the equality. Confirmed discriminating by mutating an `adjustExponent` constant and observing the new test fail. Test-only change; no production source is modified. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 27 minutes and 7 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Reviewed a64dd7d: exercise the adjustExponent logic paths in div; mutation-validated discriminating test (not enshrining). All checks green. LGTM. |
|
@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment: S/M/L PR Classification Guidelines:This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed. Small (S)Characteristics:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
Fixes #133
The
divimplementation inLibDecimalFloatImplementationselects anadjustExponentfor scaling the numerator via a binary search over the order of magnitude of the (maximized) divisor coefficient. The smaller-than-1e75leaves of that search were not exercised by the existing tests, because they are only reachable when the divisor cannot be maximized — its exponent is pinned attype(int256).min, leaving the coefficient at its given magnitude.This PR adds deterministic unit tests (test-only, no production source change) covering:
testDivAdjustExponentLeaves— every interior leaf of the binary search, placing one divisor strictly inside each sub-range (< 1e5,[1e5,1e10), ...[1e73,1e75)including the "noop" leaf that keeps the starting1e76scale).testDivAdjustExponentBoundaries— the strict<boundary comparisons at each power-of-ten boundary (1e5 .. 1e68).testDivAdjustExponentFullDivisor— the dedicated full-divisor branch (scale = 1e75,adjustExponent = 75).testDivAdjustExponentLargeDivisor— the>= 1e76path that skips the scaling block entirely (adjustExponent = 76).testDivAdjustExponentSpillsToExponentB— the adjustment spilling fromexponentAontoexponentB.testDivAdjustExponentSpillOverflowReturnsZero— the spill-overflow return-zero case.testDivUnderflowReturnsZero— the underflow return-zero case.Each case asserts the round-trip identity
(a / b) * b == a(compared as a value viaeq), which pins both the quotient mantissa and theadjustExponentconstant for that branch: a wrong constant scales the quotient by a power of ten and breaks the equality. The leaves test also asserts the exact quotient mantissa (3e75).Verification
forge buildclean.testProdDeployment{Arbitrum,Base,BaseSepolia,Flare,Polygon}fork tests that require*_RPC_URLenv vars; verified identical on cleanorigin/main.adjustExponentconstant (5→6) makestestDivAdjustExponentLeavesfail, confirming the round-trip oracle has real discriminating power; reverted before commit.🤖 Generated with Claude Code