[
{ "name": "ten pounds three ways keeps the penny", "args": [{ "minor": 1000, "currency": "GBP" }, [1, 1, 1]], "expect": [{ "minor": 334, "currency": "GBP" }, { "minor": 333, "currency": "GBP" }, { "minor": 333, "currency": "GBP" }] },
{ "name": "exact split needs no remainder", "args": [{ "minor": 500, "currency": "GBP" }, [3, 7]], "expect": [{ "minor": 150, "currency": "GBP" }, { "minor": 350, "currency": "GBP" }] },
{ "name": "weighted split distributes by largest remainder", "args": [{ "minor": 10000, "currency": "GBP" }, [1, 1, 1, 1, 1, 1]], "expect": [{ "minor": 1667, "currency": "GBP" }, { "minor": 1667, "currency": "GBP" }, { "minor": 1667, "currency": "GBP" }, { "minor": 1667, "currency": "GBP" }, { "minor": 1666, "currency": "GBP" }, { "minor": 1666, "currency": "GBP" }] },
{ "name": "credit notes split without inventing money", "args": [{ "minor": -1000, "currency": "GBP" }, [1, 1, 1]], "expect": [{ "minor": -333, "currency": "GBP" }, { "minor": -333, "currency": "GBP" }, { "minor": -334, "currency": "GBP" }] },
{ "name": "single share takes everything", "args": [{ "minor": 999, "currency": "GBP" }, [1]], "expect": [{ "minor": 999, "currency": "GBP" }] },
{ "name": "zero ratios are an error", "args": [{ "minor": 100, "currency": "GBP" }, [0, 0]], "expectError": "ratios must not sum to zero" },
{ "name": "empty ratios are an error", "args": [{ "minor": 100, "currency": "GBP" }, []], "expectError": "at least one ratio" },
{ "name": "the leftover penny goes to the largest remainder, not the first share", "args": [{ "minor": 100, "currency": "GBP" }, [1, 2]], "expect": [{ "minor": 33, "currency": "GBP" }, { "minor": 67, "currency": "GBP" }] },
{ "name": "one penny three ways: only the first share gets it", "args": [{ "minor": 1, "currency": "GBP" }, [1, 1, 1]], "expect": [{ "minor": 1, "currency": "GBP" }, { "minor": 0, "currency": "GBP" }, { "minor": 0, "currency": "GBP" }] },
{ "name": "two pennies three ways: ties go in order", "args": [{ "minor": 2, "currency": "GBP" }, [1, 1, 1]], "expect": [{ "minor": 1, "currency": "GBP" }, { "minor": 1, "currency": "GBP" }, { "minor": 0, "currency": "GBP" }] },
{ "name": "a zero ratio gets nothing", "args": [{ "minor": 1000, "currency": "GBP" }, [1, 0, 1]], "expect": [{ "minor": 500, "currency": "GBP" }, { "minor": 0, "currency": "GBP" }, { "minor": 500, "currency": "GBP" }] },
{ "name": "a zero amount splits into zeros", "args": [{ "minor": 0, "currency": "GBP" }, [1, 2]], "expect": [{ "minor": 0, "currency": "GBP" }, { "minor": 0, "currency": "GBP" }] },
{ "name": "a weighted split with a remainder", "args": [{ "minor": 1001, "currency": "GBP" }, [1, 2, 3, 4]], "expect": [{ "minor": 100, "currency": "GBP" }, { "minor": 200, "currency": "GBP" }, { "minor": 300, "currency": "GBP" }, { "minor": 401, "currency": "GBP" }] },
{ "name": "a weighted credit still adds back to the whole", "args": [{ "minor": -100, "currency": "GBP" }, [1, 2]], "expect": [{ "minor": -33, "currency": "GBP" }, { "minor": -67, "currency": "GBP" }] },
{ "name": "zero-decimal currency", "args": [{ "minor": 1000, "currency": "JPY" }, [1, 1, 1]], "expect": [{ "minor": 334, "currency": "JPY" }, { "minor": 333, "currency": "JPY" }, { "minor": 333, "currency": "JPY" }] },
{ "name": "the largest safe integer halves without losing a unit", "args": [{ "minor": 9007199254740991, "currency": "GBP" }, [1, 1]], "expect": [{ "minor": 4503599627370496, "currency": "GBP" }, { "minor": 4503599627370495, "currency": "GBP" }] },
{ "name": "ratios that cancel out are an error", "args": [{ "minor": 100, "currency": "GBP" }, [1, -1]], "expectError": "ratios must not sum to zero" }
]