Skip to content

Splitting $10.00 three ways loses a cent (#26) - #33

Closed
Param-Harrison wants to merge 2 commits into
mainfrom
factory/issue-26
Closed

Param-Harrison wants to merge 2 commits into
mainfrom
factory/issue-26

Conversation

@Param-Harrison

Copy link
Copy Markdown
Contributor

Closes #26

Summary

splitCents rounded 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 first total - base * n members, in the order passed in, each get base + 1. Shares now always add up to the total. Only src/money/cents.ts and tests/money.test.ts changed.

Acceptance criteria

AC Evidence (command / test) Result
AC-1 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}) pass
AC-2 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}) pass
AC-3 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}) pass
AC-4 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}) pass
AC-5 The 6 original tests pass unmodified, and git diff main -- tests/money.test.ts only adds lines. The zero-member throw was checked directly with bun -e "splitCents(100, [])", which printed cannot split among zero members pass
AC-6 bun run .claude/skills/handling-money/scripts/check-cents.ts: [ok ] for all 4 cases, exit 0 pass
AC-7 make check: tsc clean, 30 pass / 0 fail, all 9 skills valid, exit 0 pass

Full evidence is in the verdict comment on #26.

Non-goals respected

  • NG-1: No signature or return-type changes. formatCents, parseCents and sumCents were not edited.
  • NG-2: No edits to src/expenses.ts, src/balances.ts, src/routes/**, src/db.ts or the schema.
  • NG-3: No protected paths touched.
  • NG-4: No new handling or validation for negative or non-integer totals.
  • NG-5: Tests were only added. None were deleted or weakened.
  • NG-6: Expense shares already in the database are not repaired or migrated.
  • NG-7: Leftover cents are assigned only by position in the input array (i < remainder), not by payer, amount or ID.

The test that bites

  • Test: splitCents > splits a total smaller than the member count one cent at a time
  • Fails on main: with main's src/money/cents.ts and this branch's tests, bun test tests/money.test.ts gives 6 pass / 4 fail. This test expected a: 1, b: 1 and got a: 0, b: 0, and the other three new tests fail too.
  • Passes here: bun test tests/money.test.ts gives 10 pass / 0 fail.

Gate line

FACTORY_GATES: status=GREEN passed=3 failed=0 skipped=1 failed_gates=audit

audit is required: false in .factory/config.json. It fails because of Hono advisories that already exist on main, not because of this diff.

Protected paths touched

none

Reviewer findings addressed

Both findings are non-blocking, predate this diff and were left out of scope:

  • splitCents stores shares in a Record keyed 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.
  • No test asserts that a split among zero members throws. It was checked by hand for AC-5 (see above). Adding that test could go in the same follow-up.

Human checklist

  • AC table has real evidence, not placeholders
  • Non-goals respected
  • Gate line is GREEN
  • Protected paths are "none", or the change to them is expected and reviewed
  • I ran the test that bites myself

🤖 Generated with Claude Code

@Param-Harrison
Param-Harrison marked this pull request as ready for review September 23, 2026 19:08
@Param-Harrison
Param-Harrison deleted the factory/issue-26 branch September 23, 2026 19:28
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.

Splitting $10.00 three ways loses a cent

1 participant