[
{"name": "40 kWh at 90% efficiency draws 44.44 kWh: at 24.5p that is 1088.9p", "args": [40000, 9000, 7000, "22:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 44444, "minutes": 381, "cost": {"minor": 1089, "currency": "GBP"}}},
{"name": "the same charge with no losses costs 980p", "args": [40000, 10000, 7000, "22:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 40000, "minutes": 343, "cost": {"minor": 980, "currency": "GBP"}}},
{"name": "from 23:30 the first hour is at the day rate, the rest off-peak: 171.5p + 210p (the start-time rate alone would say 857.5p)", "args": [35000, 10000, 7000, "23:30", [{"start": "00:30", "pricePerKwhTenths": 75}, {"start": "05:30", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 35000, "minutes": 300, "cost": {"minor": 382, "currency": "GBP"}}},
{"name": "the same 381.5p rounded down", "args": [35000, 10000, 7000, "23:30", [{"start": "00:30", "pricePerKwhTenths": 75}, {"start": "05:30", "pricePerKwhTenths": 245}], "GBP", "down"], "expect": {"energyDrawnWh": 35000, "minutes": 300, "cost": {"minor": 381, "currency": "GBP"}}},
{"name": "the same 381.5p rounded half-even goes to the even 382", "args": [35000, 10000, 7000, "23:30", [{"start": "00:30", "pricePerKwhTenths": 75}, {"start": "05:30", "pricePerKwhTenths": 245}], "GBP", "half-even"], "expect": {"energyDrawnWh": 35000, "minutes": 300, "cost": {"minor": 382, "currency": "GBP"}}},
{"name": "entirely inside the off-peak window", "args": [20000, 10000, 7000, "01:00", [{"start": "00:30", "pricePerKwhTenths": 75}, {"start": "05:30", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 20000, "minutes": 172, "cost": {"minor": 150, "currency": "GBP"}}},
{"name": "running past the end of off-peak: 18.5 kWh at 7.5p then 6.5 kWh at 24.5p", "args": [25000, 10000, 7400, "03:00", [{"start": "00:30", "pricePerKwhTenths": 75}, {"start": "05:30", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 25000, "minutes": 203, "cost": {"minor": 298, "currency": "GBP"}}},
{"name": "a slow charge over four days and four hours crosses every window many times", "args": [10000, 10000, 100, "00:00", [{"start": "00:00", "pricePerKwhTenths": 100}, {"start": "12:00", "pricePerKwhTenths": 200}], "GBP", "half-up"], "expect": {"energyDrawnWh": 10000, "minutes": 6000, "cost": {"minor": 148, "currency": "GBP"}}},
{"name": "before the first window of the day the last one still applies, wrapping past midnight", "args": [7000, 10000, 7000, "06:00", [{"start": "07:00", "pricePerKwhTenths": 300}, {"start": "23:00", "pricePerKwhTenths": 100}], "GBP", "half-up"], "expect": {"energyDrawnWh": 7000, "minutes": 60, "cost": {"minor": 70, "currency": "GBP"}}},
{"name": "starting exactly on a window's start takes that window's price", "args": [7000, 10000, 7000, "07:00", [{"start": "07:00", "pricePerKwhTenths": 300}, {"start": "23:00", "pricePerKwhTenths": 100}], "GBP", "half-up"], "expect": {"energyDrawnWh": 7000, "minutes": 60, "cost": {"minor": 210, "currency": "GBP"}}},
{"name": "nothing added costs nothing and takes no time", "args": [0, 9000, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expect": {"energyDrawnWh": 0, "minutes": 0, "cost": {"minor": 0, "currency": "GBP"}}},
{"name": "a rapid charger in euro cents: 50 kWh at 94% and 150 kW", "args": [50000, 9400, 150000, "14:10", [{"start": "00:00", "pricePerKwhTenths": 590}], "EUR", "half-up"], "expect": {"energyDrawnWh": 53191, "minutes": 22, "cost": {"minor": 3138, "currency": "EUR"}}},
{"name": "an empty tariff is an error", "args": [1000, 9000, 7000, "12:00", [], "GBP", "half-up"], "expectError": "tariff must have at least one window"},
{"name": "windows out of order are an error", "args": [1000, 9000, 7000, "12:00", [{"start": "05:30", "pricePerKwhTenths": 245}, {"start": "00:30", "pricePerKwhTenths": 75}], "GBP", "half-up"], "expectError": "tariff windows must be in ascending order of start time"},
{"name": "two windows starting at the same time are an error", "args": [1000, 9000, 7000, "12:00", [{"start": "00:30", "pricePerKwhTenths": 245}, {"start": "00:30", "pricePerKwhTenths": 75}], "GBP", "half-up"], "expectError": "tariff windows must be in ascending order of start time"},
{"name": "24:00 is not a start time", "args": [1000, 9000, 7000, "24:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "startTime must be HH:MM, 00:00 to 23:59"},
{"name": "a tariff window time without a leading zero is an error", "args": [1000, 9000, 7000, "12:00", [{"start": "0:30", "pricePerKwhTenths": 75}], "GBP", "half-up"], "expectError": "tariff start must be HH:MM, 00:00 to 23:59"},
{"name": "zero efficiency is an error", "args": [1000, 0, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "efficiencyBasisPoints must be a whole number from 1 to 10000"},
{"name": "more than 100% efficiency is an error", "args": [1000, 10001, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "efficiencyBasisPoints must be a whole number from 1 to 10000"},
{"name": "zero charger power is an error", "args": [1000, 9000, 0, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "chargerPowerWatts must be a whole number from 1 to 1000000"},
{"name": "negative energy is an error", "args": [-1, 9000, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "energyAddedWh must be a whole number from 0 to 1000000"},
{"name": "fractional watt hours are an error", "args": [1000.5, 9000, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "GBP", "half-up"], "expectError": "energyAddedWh must be a whole number"},
{"name": "a negative price is an error", "args": [1000, 9000, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": -1}], "GBP", "half-up"], "expectError": "pricePerKwhTenths must be a whole number, 0 or more"},
{"name": "a bad currency is an error", "args": [1000, 9000, 7000, "12:00", [{"start": "00:00", "pricePerKwhTenths": 245}], "pounds", "half-up"], "expectError": "is not an uppercase ISO 4217 currency code"}
]