Formalizes a pattern repeated by hand all session: copy the current whole-base plan, add a building/recipe, diff simulate() against the baseline for the true marginal profit and capex (not PRUNplanner's plan-level ROI, which divides whole-plan profit by only the new capex and badly overstates once a base exists). Also flags any workforce tier the addition newly overloads, distinct from a pre-existing overload it didn't cause - this is what caught the PP2/pioneer-housing and 2nd-CHP/pioneer-housing surprises by hand before this tool existed. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
30 lines
987 B
Python
30 lines
987 B
Python
from pathlib import Path
|
|
import sys
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "tools"))
|
|
import whatif
|
|
|
|
|
|
def test_apply_add_reuses_existing_recipe():
|
|
spec = {"buildings": [{"building": "POL", "amount": 1, "recipes": ["EPO,PG=>DEC"]}]}
|
|
whatif.apply_add(spec, "POL:1")
|
|
assert spec["buildings"] == [{"building": "POL", "amount": 2, "recipes": ["EPO,PG=>DEC"]}]
|
|
|
|
|
|
def test_apply_add_new_building_needs_explicit_recipe():
|
|
spec = {"buildings": []}
|
|
import pytest
|
|
with pytest.raises(SystemExit):
|
|
whatif.apply_add(spec, "CHP:1")
|
|
|
|
|
|
def test_apply_add_appends_new_building_with_recipe():
|
|
spec = {"buildings": []}
|
|
whatif.apply_add(spec, "CHP:1:MG,S,CU=>IND")
|
|
assert spec["buildings"] == [{"building": "CHP", "amount": 1, "recipes": ["MG,S,CU=>IND"]}]
|
|
|
|
|
|
def test_apply_infra_adds_delta():
|
|
spec = {"infrastructure": {"HB1": 4}}
|
|
whatif.apply_infra(spec, "HB1:+1,HB2:+2")
|
|
assert spec["infrastructure"] == {"HB1": 5, "HB2": 2}
|