Files
AIPortPilot/backend/tests/test_health_calculator.py
selfrelease fad458b2a7 docs(uiux): UIUX 设计方案大改 + 5 份作业指导书对齐 + 开发任务文档
- UIUX 文档:填充 19 个缺口(多主体画像/健康度/AI+看板/增长域/洞察域/创始人端/OODA/助推/商密)
- UIUX 文档:插入 6 个新章节(十四~十九),旧章节重编号为二十~三十一,更新目录和交叉引用
- 作业指导书 x5:导航改为 6 域分组,新增 Context Bar/工作模式/Insight Rail/决策线程/多工作区等 UI 概念
- 新建 docs/2-task-uiux.md:50 个代码落地开发任务,按 P0-P6 分优先级 + 8 Sprint 规划
- 后端/前端:大量新增模型、路由、组件(来自之前 Phase 开发)
2026-07-19 11:53:38 +08:00

66 lines
2.1 KiB
Python

"""健康度计算引擎测试。"""
from app.services.health_calculator import calculate_health_score, determine_trend
class TestCalculateHealthScore:
"""健康度评分计算。"""
def test_empty_data(self):
"""空数据应返回全 0。"""
result = calculate_health_score({})
assert result["total_score"] == 0.0
assert result["financial_score"] == 0.0
def test_healthy_company(self):
"""健康企业:跑道充足 + 营收增长 + 烧钱下降。"""
data = {
"revenue": {"yoy_change": "30"},
"cash_balance": {"runway_months": 18},
"burn_rate": {"trend": "down"},
"headcount": {"new_hires": 5, "departures": 1},
"key_metrics": [{"name": "ARR", "change": "+25%"}],
}
result = calculate_health_score(data)
assert result["total_score"] >= 69
assert result["financial_score"] > 80
def test_unhealthy_company(self):
"""不健康企业:跑道短 + 营收下滑 + 烧钱上升。"""
data = {
"revenue": {"yoy_change": "-20"},
"cash_balance": {"runway_months": 2},
"burn_rate": {"trend": "up"},
"headcount": {"new_hires": 0, "departures": 8},
}
result = calculate_health_score(data)
assert result["total_score"] < 50
assert result["financial_score"] < 30
def test_score_range(self):
"""评分应在 0-100 范围内。"""
data = {
"revenue": {"yoy_change": "1000"},
"cash_balance": {"runway_months": 100},
"burn_rate": {"trend": "down"},
}
result = calculate_health_score(data)
for key, val in result.items():
assert 0 <= val <= 100
class TestDetermineTrend:
"""趋势判断。"""
def test_up(self):
assert determine_trend(80, 60) == "up"
def test_down(self):
assert determine_trend(50, 70) == "down"
def test_stable(self):
assert determine_trend(60, 62) == "stable"
def test_no_previous(self):
assert determine_trend(70, None) == "stable"