[
{"name": "30.00 over 30 days, 10 used: an even split needs no help", "args": [{"minor": 3000, "currency": "GBP"}, 30, 10], "expect": {"total": {"minor": 3000, "currency": "GBP"}, "used": {"minor": 1000, "currency": "GBP"}, "unused": {"minor": 2000, "currency": "GBP"}}},
{"name": "99.00 over a 31 day month, 10 days used: the odd penny goes to the used side", "args": [{"minor": 9900, "currency": "GBP"}, 31, 10], "expect": {"total": {"minor": 9900, "currency": "GBP"}, "used": {"minor": 3194, "currency": "GBP"}, "unused": {"minor": 6706, "currency": "GBP"}}},
{"name": "9.99 over two days: two independent roundings would invent a penny, allocate does not", "args": [{"minor": 999, "currency": "GBP"}, 2, 1], "expect": {"total": {"minor": 999, "currency": "GBP"}, "used": {"minor": 500, "currency": "GBP"}, "unused": {"minor": 499, "currency": "GBP"}}},
{"name": "nothing used yet, so the whole charge is still unused", "args": [{"minor": 9900, "currency": "GBP"}, 31, 0], "expect": {"total": {"minor": 9900, "currency": "GBP"}, "used": {"minor": 0, "currency": "GBP"}, "unused": {"minor": 9900, "currency": "GBP"}}},
{"name": "the full period used leaves nothing unused", "args": [{"minor": 9900, "currency": "GBP"}, 31, 31], "expect": {"total": {"minor": 9900, "currency": "GBP"}, "used": {"minor": 9900, "currency": "GBP"}, "unused": {"minor": 0, "currency": "GBP"}}},
{"name": "one day of a 365 day annual plan", "args": [{"minor": 1000000, "currency": "GBP"}, 365, 1], "expect": {"total": {"minor": 1000000, "currency": "GBP"}, "used": {"minor": 2740, "currency": "GBP"}, "unused": {"minor": 997260, "currency": "GBP"}}},
{"name": "a credit note prorates the same way and still sums to the credit", "args": [{"minor": -9900, "currency": "GBP"}, 31, 10], "expect": {"total": {"minor": -9900, "currency": "GBP"}, "used": {"minor": -3194, "currency": "GBP"}, "unused": {"minor": -6706, "currency": "GBP"}}},
{"name": "a free plan splits into nothing and nothing", "args": [{"minor": 0, "currency": "GBP"}, 30, 10], "expect": {"total": {"minor": 0, "currency": "GBP"}, "used": {"minor": 0, "currency": "GBP"}, "unused": {"minor": 0, "currency": "GBP"}}},
{"name": "100.00 over a seven day trial, three days used", "args": [{"minor": 10000, "currency": "GBP"}, 7, 3], "expect": {"total": {"minor": 10000, "currency": "GBP"}, "used": {"minor": 4286, "currency": "GBP"}, "unused": {"minor": 5714, "currency": "GBP"}}},
{"name": "an awkward amount over a leap year, mid-period", "args": [{"minor": 99999, "currency": "GBP"}, 366, 213], "expect": {"total": {"minor": 99999, "currency": "GBP"}, "used": {"minor": 58196, "currency": "GBP"}, "unused": {"minor": 41803, "currency": "GBP"}}},
{"name": "yen has no minor unit, so the odd whole yen goes to the larger remainder", "args": [{"minor": 1000, "currency": "JPY"}, 3, 1], "expect": {"total": {"minor": 1000, "currency": "JPY"}, "used": {"minor": 333, "currency": "JPY"}, "unused": {"minor": 667, "currency": "JPY"}}},
{"name": "a zero day period is an error, not a division by zero", "args": [{"minor": 9900, "currency": "GBP"}, 0, 0], "expectError": "must be greater than zero"},
{"name": "a negative period is an error", "args": [{"minor": 9900, "currency": "GBP"}, -31, 0], "expectError": "must be greater than zero"},
{"name": "using more days than the period has is an error, not a clamp", "args": [{"minor": 9900, "currency": "GBP"}, 31, 32], "expectError": "must not exceed total days"},
{"name": "negative usage is an error", "args": [{"minor": 9900, "currency": "GBP"}, 31, -1], "expectError": "must not be negative"},
{"name": "a fractional period length is an error: days are whole here", "args": [{"minor": 9900, "currency": "GBP"}, 30.5, 10], "expectError": "must be greater than zero"}
]