39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
|
|
# ============================================================
|
|||
|
|
# SC-06 敏感性分析黄金测试
|
|||
|
|
# ============================================================
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
from server.aps_domain.sensitivity import run_sensitivity
|
|||
|
|
from server.state.seed import seed_world
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_sensitivity_does_not_mutate_world():
|
|||
|
|
world = seed_world()
|
|||
|
|
before = json.dumps(world, ensure_ascii=False, sort_keys=True)
|
|||
|
|
report = run_sensitivity(world, strategy="COMPREHENSIVE")
|
|||
|
|
after = json.dumps(world, ensure_ascii=False, sort_keys=True)
|
|||
|
|
assert before == after
|
|||
|
|
assert report["baseline"]["poCount"] >= 1
|
|||
|
|
assert len(report["rows"]) >= 4
|
|||
|
|
assert report["rows"][0]["swing"] >= report["rows"][-1]["swing"]
|
|||
|
|
assert "Tornado" in report["markdown"]
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_sensitivity_buffer_affects_tardiness_direction():
|
|||
|
|
"""更紧的交期缓冲(0.85)相对 1.0 不应减少延期(通常升高或持平)。"""
|
|||
|
|
world = seed_world()
|
|||
|
|
report = run_sensitivity(world, strategy="COMPREHENSIVE")
|
|||
|
|
buf = next(r for r in report["rows"] if r["factorId"] == "deliveryBufferRatio")
|
|||
|
|
# low=0.85(更紧), high=1.00(更松)
|
|||
|
|
assert buf["low"]["tardiness"] >= buf["high"]["tardiness"] - 1e-6
|
|||
|
|
|
|||
|
|
|
|||
|
|
def test_sensitivity_efficiency_low_worsens_or_equals():
|
|||
|
|
world = seed_world()
|
|||
|
|
report = run_sensitivity(world, strategy="FIFO")
|
|||
|
|
eff = next(r for r in report["rows"] if r["factorId"] == "lineEfficiency")
|
|||
|
|
# 效率×0.8 相对 ×1.2:延期不应更低
|
|||
|
|
assert eff["low"]["tardiness"] >= eff["high"]["tardiness"] - 1e-6
|