From d3a4426ca47827385d29a2f3b88aed073908238e Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 24 Jun 2026 17:39:58 +0000 Subject: [PATCH] =?UTF-8?q?Lock=20whole-meter=20off-peak=20routing=20and?= =?UTF-8?q?=20standard-meter=20no-op=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- tests/domain/billing/test_energy_breakdown.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/domain/billing/test_energy_breakdown.py b/tests/domain/billing/test_energy_breakdown.py index d7fdb7bc..f754bc66 100644 --- a/tests/domain/billing/test_energy_breakdown.py +++ b/tests/domain/billing/test_energy_breakdown.py @@ -184,3 +184,50 @@ def test_off_peak_heating_line_carries_its_carrier_and_high_rate_fraction() -> N 9000.0, 0.0, ) + + +def test_off_peak_meter_routes_every_electric_use_to_the_off_peak_carrier() -> None: + # Arrange — a gas-heated dwelling that happens to be on an Off-Peak Meter: + # the gas heating stays gas, but ALL electric uses (lighting, appliances, + # pumps) bill on the off-peak carrier, the "other" uses sharing the + # ALL_OTHER_USES fraction and pumps/fans carrying their own. + result = _sap_result( + main_heating_fuel_kwh_per_yr=8000.0, + main_heating_fuel_code=1, # mains gas — single-rate, unaffected + lighting_kwh_per_yr=400.0, + appliances_kwh_per_yr=1900.0, + pumps_fans_kwh_per_yr=200.0, + is_off_peak_meter=True, + other_electricity_high_rate_fraction=0.90, + pumps_fans_high_rate_fraction=0.71, + ) + + # Act + breakdown = EnergyBreakdown.from_sap_result(result) + + # Assert + by_section = {line.section: line for line in breakdown.lines} + assert by_section[BillSection.HEATING].fuel is Fuel.MAINS_GAS + assert by_section[BillSection.HEATING].high_rate_fraction is None + assert by_section[BillSection.LIGHTING].fuel is Fuel.ELECTRICITY_OFF_PEAK + assert by_section[BillSection.LIGHTING].high_rate_fraction == 0.90 + assert by_section[BillSection.APPLIANCES].fuel is Fuel.ELECTRICITY_OFF_PEAK + assert by_section[BillSection.APPLIANCES].high_rate_fraction == 0.90 + assert by_section[BillSection.PUMPS_FANS].high_rate_fraction == 0.71 + + +def test_standard_meter_keeps_electric_uses_on_flat_rate_electricity() -> None: + # Arrange — electric heating on a standard meter: no day/night split anywhere. + result = _sap_result( + main_heating_fuel_kwh_per_yr=6000.0, + main_heating_fuel_code=30, # standard-tariff electricity + lighting_kwh_per_yr=400.0, + is_off_peak_meter=False, + ) + + # Act + breakdown = EnergyBreakdown.from_sap_result(result) + + # Assert — every line is flat-rate ELECTRICITY with no high-rate fraction. + assert all(line.fuel is Fuel.ELECTRICITY for line in breakdown.lines) + assert all(line.high_rate_fraction is None for line in breakdown.lines)