Splitting $10.00 three ways loses a cent (#61) - #67
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #61
Summary
splitCentsnow gives leftover cents to the first members, following the remainder rule inhandling-money/references/rules.md, so shares always add up to exactly the original total. Before this fix, 1000 split three ways gave 333/333/333, which sums to 999. It now gives 334/333/333. Onlysrc/money/cents.tsandtests/money.test.tschanged.Acceptance criteria
bun test tests/money.test.ts:splitCents > gives leftover cents to the first membersreturns{ a: 334, b: 333, c: 333 }bun test tests/money.test.ts:splitCents > shares always sum to the total for uneven splits. For 1001/3, 1/3, 2/3, 1000/7, 999/4 and 5/1, the shares sum to the total, max − min ≤ 1, and the extra cents go to the leading membersbun test tests/money.test.ts→9 pass, 0 fail. The existing even-split tests pass, and so does the zero-members throwbun run .claude/skills/handling-money/scripts/check-cents.ts→[ok ] split(1000, 3 members) -> sum 1000 (expected 1000), and every case is[ok]make check:tsc --noEmitis clean,bun testgives 29 pass and 0 fail, and all 9 skills are valid. The gate line is belowFull per-AC evidence is in the verdict comment on #61.
Non-goals respected
splitCentssignature, itsRecord<string, number>return type and its zero-members error are unchanged.src/money/cents.tsandtests/money.test.tschanged.src/expenses.ts, the routes, the schema and the API shape were not touched.check-cents.ts.Math.floorplus the integer remainder.The test that bites
splitCents > gives leftover cents to the first members(alsosplitCents > shares always sum to the total for uneven splits)main:bun test tests/money.test.tsagainstmain'ssrc/money/cents.ts→Expected {a: 334, ...}, Received {a: 333, ...}andExpected: 1001, Received: 999. Onmain,check-cents.tsalso prints[FAIL] split(1000, 3 members) -> sum 999 (expected 1000)bun test tests/money.test.ts→9 pass, 0 failGate line
The audit gate was skipped, not failed:
failed=0.Protected paths touched
noneReviewer findings addressed
none
Human checklist
🤖 Generated with Claude Code