import { describe, expect, it } from 'vitest' import { computeSplit } from './split' describe('computeSplit', () => { it('divides evenly when amount divides cleanly', () => { expect(computeSplit(1000, [1, 2, 4])).toEqual({ 1: 334, 2: 333, 4: 333 }) }) it('sums back exactly to the original amount', () => { const shares = computeSplit(1001, [1, 2, 3, 4, 5, 6, 7]) const total = Object.values(shares).reduce((sum, share) => sum + share, 0) expect(total).toBe(1001) }) it('distributes remainder cents one-each to the first participants in order', () => { expect(computeSplit(10, [1, 2, 3])).toEqual({ 1: 4, 2: 3, 3: 3 }) }) it('gives the full amount to a single participant', () => { expect(computeSplit(1234, [9])).toEqual({ 9: 1234 }) }) it('handles a zero amount', () => { expect(computeSplit(0, [1, 2])).toEqual({ 1: 0, 2: 0 }) }) it('throws when given no participants', () => { expect(() => computeSplit(1000, [])).toThrow() }) })