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.
27 lines
783 B
Python
27 lines
783 B
Python
import pytest
|
|
|
|
from app.algorithms.demand_allocation import allocate_demand_by_pipe_length
|
|
|
|
|
|
def test_allocate_demand_by_incident_pipe_length():
|
|
nodes = {
|
|
"J1": {"type": "junction", "links": ["P1"]},
|
|
"J2": {"type": "junction", "links": ["P1", "P2"]},
|
|
"R1": {"type": "reservoir", "links": ["P2"]},
|
|
}
|
|
links = {"P1": {"length": 100.0}, "P2": {"length": 300.0}}
|
|
|
|
result = allocate_demand_by_pipe_length(80.0, nodes, links)
|
|
|
|
assert result == {"J1": pytest.approx(10.0), "J2": pytest.approx(40.0)}
|
|
|
|
|
|
def test_allocate_demand_returns_empty_for_zero_length_topology():
|
|
result = allocate_demand_by_pipe_length(
|
|
80.0,
|
|
{"J1": {"type": "junction", "links": ["P1"]}},
|
|
{"P1": {"length": 0.0}},
|
|
)
|
|
|
|
assert result == {}
|