A helper that rounds to two decimal places, and a bill splitter built on top of it. The remainder exists because thirds of a pound do not divide evenly, and somebody has to be told about the penny that is left over.
The module under test
| 1 | export function roundMoney(amount) { | ||
| 2 | return Math.round(amount * 100) / 100; | ||
| 3 | } | ||
| 4 | |||
| 5 | export function splitBill(total, people) { | ||
| 6 | if (people <= 0) { | ||
| 7 | throw new Error("Need at least one person to split between"); | ||
| 8 | } | ||
| 9 | const share = roundMoney(total / people); | ||
| 10 | const remainder = roundMoney(total - share * people); | ||
| 11 | return { share, remainder }; | ||
| 12 | } | ||
| 13 |
Your tests
Mutants
0%
Mutation score
- Survived
- 0
- Killed
- 0 / 0
- Line coverage
- —
- Tests
- 0
- Assertion width
- —
- Cycle
- —
survivedkilledtimed outequivalentnot run