pump / backend /tests /test_forecaster.py
Codex
Deploy efficiency estimate fix cf55248
aec7019
Raw History Blame Contribute Delete
1.02 kB
from app.models.forecaster import FlowForecaster
def test_material_balance_inflow():
fc = FlowForecaster(wet_well_area=20.0)
# 液位不变 → 入流≈出流
fc.update(0.0, 3.0, 300.0)
q_in = fc.update(1.0, 3.0, 300.0)
assert abs(q_in - 300.0) < 1.0
# 液位上升 → 入流 > 出流
q_in2 = fc.update(2.0, 3.01, 300.0)
assert q_in2 > 300.0
def test_linear_trend_prediction():
fc = FlowForecaster(wet_well_area=20.0, window=100)
# 构造液位平稳、出流线性上升的场景
level = 3.0
for t in range(60):
fc.update(float(t), level, 200.0 + t * 2.0)
pred = fc.predict(horizon_s=10.0)
assert pred is not None
# 上升趋势应外推出高于当前均值的值
assert pred > fc.current_avg()
def test_falls_back_to_mean_when_insufficient():
fc = FlowForecaster()
assert fc.predict() is None or fc.predict() == 0.0
fc.update(0.0, 3.0, 250.0)
fc.update(1.0, 3.0, 250.0)
assert abs(fc.predict() - fc.current_avg()) < 1e-6