Skip to content

Splitting $10.00 three ways loses a cent (#61) - #67

Merged
Param-Harrison merged 2 commits into
mainfrom
factory/issue-61
Sep 24, 2026
Merged

Param-Harrison merged 2 commits into
mainfrom
factory/issue-61

Conversation

@Param-Harrison

Copy link
Copy Markdown
Contributor

Closes #61

Summary

splitCents now gives leftover cents to the first members, following the remainder rule in handling-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. 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 leftover cents to the first members returns { a: 334, b: 333, c: 333 } pass
AC-2 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 members pass
AC-3 bun test tests/money.test.ts → 9 pass, 0 fail. The existing even-split tests pass, and so does the zero-members throw pass
AC-4 bun run .claude/skills/handling-money/scripts/check-cents.ts → [ok ] split(1000, 3 members) -> sum 1000 (expected 1000), and every case is [ok] pass
AC-5 make check: tsc --noEmit is clean, bun test gives 29 pass and 0 fail, and all 9 skills are valid. The gate line is below pass

Full per-AC evidence is in the verdict comment on #61.

Non-goals respected

  • NG-1: The splitCents signature, its Record<string, number> return type and its zero-members error are unchanged.
  • NG-2: Only src/money/cents.ts and tests/money.test.ts changed. src/expenses.ts, the routes, the schema and the API shape were not touched.
  • NG-3: This PR adds no handling for negative or non-integer totals.
  • NG-4: No protected paths were touched, including the handling-money skill and check-cents.ts.
  • NG-5: The fix uses no float arithmetic, only Math.floor plus the integer remainder.

The test that bites

  • Test: splitCents > gives leftover cents to the first members (also splitCents > shares always sum to the total for uneven splits)
  • Fails on main: bun test tests/money.test.ts against main's src/money/cents.ts → Expected {a: 334, ...}, Received {a: 333, ...} and Expected: 1001, Received: 999. On main, check-cents.ts also prints [FAIL] split(1000, 3 members) -> sum 999 (expected 1000)
  • Passes here: bun test tests/money.test.ts → 9 pass, 0 fail

Gate line

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

The audit gate was skipped, not failed: failed=0.

Protected paths touched

none

Reviewer findings addressed

none

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 24, 2026 11:41
@Param-Harrison
Param-Harrison merged commit 929fe55 into main Sep 24, 2026
1 check passed
@Param-Harrison
Param-Harrison deleted the factory/issue-61 branch September 24, 2026 14:29
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