summaryrefslogtreecommitdiff
path: root/evals/fixtures/test-driven-development/README.md
blob: a8458a7a35eb32b9f1f47a3f7ae5d7ec310145e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# split-payment

Utility for splitting an amount of money among `n` participants without
losing or inventing cents. Amounts are integer cents throughout; the
library never touches floating point.

## API

`splitCents(totalCents, n)` returns an array of `n` integer cent amounts.
`totalCents` is a non-negative integer, `n` is a positive integer.

## Invariants

Every result must satisfy both invariants, for every input:

1. **Exactness** — the shares sum to exactly `totalCents`. Money is never
   lost or created.
2. **Fairness** — no two shares differ by more than one cent. When the
   total does not divide evenly, the leftover cents go to the earliest
   shares, one cent each.

For example, `splitCents(100, 7)` is `[15, 15, 14, 14, 14, 14, 14]`.

## Tests

```
npm test
```