Reorganize algorithm packages by business responsibility, move orchestration into services, and keep database access behind pooled repositories. Harden analysis API validation, remove unsafe legacy simulation endpoints, and add regression and architecture boundary coverage. BREAKING CHANGE: legacy algorithm module paths and obsolete simulation endpoints are removed.
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from app.algorithms.valve_isolation import topology_search as valve
|
|
|
|
|
|
def test_non_isolatable_omits_affected_node_ids_but_keeps_count():
|
|
links = ["P-1:pipe:A:B", "P-2:pipe:B:C", "V-optional:valve:A:C"]
|
|
|
|
result = valve.valve_isolation_analysis(links, "P-1")
|
|
|
|
assert result["isolatable"] is False
|
|
assert result["affected_node_count"] == 3
|
|
assert result["affected_nodes"] == []
|
|
assert result["optional_valves"] == ["V-optional"]
|
|
|
|
|
|
def test_isolatable_keeps_affected_node_ids_and_count():
|
|
links = ["P-1:pipe:A:B", "V-close:valve:B:C"]
|
|
|
|
result = valve.valve_isolation_analysis(links, "P-1")
|
|
|
|
assert result["isolatable"] is True
|
|
assert result["affected_node_count"] == 2
|
|
assert result["affected_nodes"] == ["A", "B"]
|
|
assert result["must_close_valves"] == ["V-close"]
|
|
|
|
|
|
def test_disabled_valve_expands_affected_area_before_counting():
|
|
links = [
|
|
"P-1:pipe:A:B",
|
|
"V-disabled:valve:B:C",
|
|
"V-close:valve:C:D",
|
|
]
|
|
result = valve.valve_isolation_analysis(
|
|
links,
|
|
"P-1",
|
|
disabled_valves=["V-disabled"],
|
|
)
|
|
|
|
assert result["isolatable"] is True
|
|
assert result["affected_node_count"] == 3
|
|
assert result["affected_nodes"] == ["A", "B", "C"]
|
|
assert result["must_close_valves"] == ["V-close"]
|