From 8548b8304b17122215eaf1260e67008c00648831 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 21 Jul 2026 10:04:48 +0000 Subject: [PATCH] =?UTF-8?q?Sell=20no=20works=20to=20a=20dwelling=20already?= =?UTF-8?q?=20at=20the=20goal=20band=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../test_modelling_goal_band_floor.py | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/orchestration/test_modelling_goal_band_floor.py diff --git a/tests/orchestration/test_modelling_goal_band_floor.py b/tests/orchestration/test_modelling_goal_band_floor.py new file mode 100644 index 000000000..3238fa477 --- /dev/null +++ b/tests/orchestration/test_modelling_goal_band_floor.py @@ -0,0 +1,42 @@ +"""The Optimiser judges "already at the goal band" on the *published* rating. + +A dwelling is in a band by the rating published on its EPC — the continuous SAP +rounded half up. The Optimiser works in continuous SAP, so a goal of "reach band +X" has to be met at the point the published rating enters band X (the integer +floor less half a point), not at the integer floor itself. Comparing a +continuous score against the integer floor makes a dwelling that already +publishes in the band read as a fraction short, and the Optimiser buys the +cheapest measure to close a gap that does not exist (#1652 / #1654 — 630 homes +in portfolio 796 published at SAP 69 / band C, each sold ~1 marginal SAP point +of works toward a band they had already reached). + +End-to-end through ``run_modelling`` (no database) with the real calculator, +against Elmhurst certs that sit in the boundary window. +""" + +from __future__ import annotations + +from datatypes.epc.domain.epc_property_data import EpcPropertyData +from domain.modelling.plan import Plan +from harness.console import run_modelling +from tests.domain.modelling._elmhurst_recommendation import ( + parse_recommendation_summary, +) + + +def _dwelling(fixture: str) -> EpcPropertyData: + return parse_recommendation_summary(fixture) + + +def test_dwelling_published_at_the_goal_band_is_sold_no_works() -> None: + # Arrange — cert 001431 with a flat roof scores a continuous 54.575, which + # publishes as SAP 55: exactly the band D floor, so the dwelling already IS + # band D. Against an integer floor of 55 it reads as 0.425 short. + already_band_d = _dwelling("flat_roof_001431_before.pdf") + + # Act — ask for the band it is already in. + plan: Plan = run_modelling(already_band_d, goal_band="D", print_table=False) + + # Assert — nothing to buy: the goal is already met. + assert plan.measures == () + assert plan.cost_of_works == 0.0