Splitting $10.00 three ways loses a cent (#26) - #33
Closed
Param-Harrison wants to merge 2 commits into
Closed
Param-Harrison wants to merge 2 commits into
Param-Harrison wants to merge 2 commits into
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 #26
Summary
splitCentsrounded every share down and dropped the leftover, so 1000 cents split 3 ways came to 333/333/333 (999 in total). It now applies the remainder rule from.claude/skills/handling-money/references/rules.md:base = floor(total / n), and the firsttotal - base * nmembers, in the order passed in, each getbase + 1. Shares now always add up to the total. Onlysrc/money/cents.tsandtests/money.test.tschanged.Acceptance criteria
bun test tests/money.test.ts:splitCents > gives the leftover cent to the first member when splitting 1000 three ways(1000 →{a:334,b:333,c:333})bun test tests/money.test.ts:splitCents > assigns leftover cents so the shares sum to the total(101/5 →{a:21,b:20,c:20,d:20,e:20})bun test tests/money.test.ts:splitCents > gives leftover cents to the first members in member order(["c","a","d","b"], 1002 →{c:251,a:251,d:250,b:250})bun test tests/money.test.ts:splitCents > splits a total smaller than the member count one cent at a time(2/5 →{a:1,b:1,c:0,d:0,e:0})git diff main -- tests/money.test.tsonly adds lines. The zero-member throw was checked directly withbun -e "splitCents(100, [])", which printedcannot split among zero membersbun run .claude/skills/handling-money/scripts/check-cents.ts:[ok ]for all 4 cases, exit 0make check:tscclean, 30 pass / 0 fail, all 9 skills valid, exit 0Full evidence is in the verdict comment on #26.
Non-goals respected
formatCents,parseCentsandsumCentswere not edited.src/expenses.ts,src/balances.ts,src/routes/**,src/db.tsor the schema.i < remainder), not by payer, amount or ID.The test that bites
splitCents > splits a total smaller than the member count one cent at a timemain: withmain'ssrc/money/cents.tsand this branch's tests,bun test tests/money.test.tsgives 6 pass / 4 fail. This test expecteda: 1, b: 1and gota: 0, b: 0, and the other three new tests fail too.bun test tests/money.test.tsgives 10 pass / 0 fail.Gate line
auditisrequired: falsein.factory/config.json. It fails because of Hono advisories that already exist onmain, not because of this diff.Protected paths touched
noneReviewer findings addressed
Both findings are non-blocking, predate this diff and were left out of scope:
splitCentsstores shares in aRecordkeyed by member ID, so duplicate member IDs collapse into one entry and the shares no longer add up to the total. This needs its own follow-up issue.Human checklist
🤖 Generated with Claude Code