소형 건설업체(100억 미만)를 위한 AI 기반 토목공사 통합관리 플랫폼 Backend (FastAPI): - SQLAlchemy 모델 13개 (users, projects, wbs, tasks, daily_reports, reports, inspections, quality, weather, permits, rag, settings) - API 라우터 11개 (auth, projects, tasks, daily_reports, reports, inspections, weather, rag, kakao, permits, settings) - Services: Claude AI 래퍼, CPM Gantt 계산, 기상청 API, RAG(pgvector), 카카오 Skill API - Alembic 마이그레이션 (pgvector 포함) - pytest 테스트 (CPM, 날씨 경보) Frontend (Next.js 15): - 11개 페이지 (대시보드, 프로젝트, Gantt, 일보, 검측, 품질, 날씨, 인허가, RAG, 설정) - TanStack Query + Zustand + Tailwind CSS 인프라: - Docker Compose (PostgreSQL pgvector + backend + frontend) - 한국어 README 및 설치 가이드 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
"""Tests for CPM Gantt calculation."""
|
|
import pytest
|
|
from datetime import date
|
|
from unittest.mock import MagicMock
|
|
import uuid
|
|
from app.services.gantt import compute_cpm
|
|
|
|
|
|
def make_task(name: str, start: str, end: str) -> MagicMock:
|
|
t = MagicMock()
|
|
t.id = uuid.uuid4()
|
|
t.name = name
|
|
t.planned_start = date.fromisoformat(start)
|
|
t.planned_end = date.fromisoformat(end)
|
|
return t
|
|
|
|
|
|
def make_dep(pred_id, succ_id) -> MagicMock:
|
|
d = MagicMock()
|
|
d.predecessor_id = pred_id
|
|
d.successor_id = succ_id
|
|
return d
|
|
|
|
|
|
def test_cpm_no_dependencies():
|
|
tasks = [
|
|
make_task("A", "2026-04-01", "2026-04-05"),
|
|
make_task("B", "2026-04-01", "2026-04-10"),
|
|
]
|
|
result = compute_cpm(tasks, [])
|
|
assert isinstance(result, tuple)
|
|
cpm_data, duration = result
|
|
assert len(cpm_data) == 2
|
|
assert duration > 0
|
|
|
|
|
|
def test_cpm_serial_tasks():
|
|
t1 = make_task("A", "2026-04-01", "2026-04-05")
|
|
t2 = make_task("B", "2026-04-06", "2026-04-10")
|
|
dep = make_dep(t1.id, t2.id)
|
|
|
|
result = compute_cpm([t1, t2], [dep])
|
|
assert isinstance(result, tuple)
|
|
cpm_data, duration = result
|
|
|
|
# Serial tasks: both should be critical
|
|
assert cpm_data[t1.id]["is_critical"] is True
|
|
assert cpm_data[t2.id]["is_critical"] is True
|
|
|
|
|
|
def test_cpm_parallel_tasks():
|
|
"""In parallel paths, only the longer path is critical."""
|
|
t_start = make_task("Start", "2026-04-01", "2026-04-02")
|
|
t_long = make_task("Long Path", "2026-04-03", "2026-04-20") # 18 days
|
|
t_short = make_task("Short Path", "2026-04-03", "2026-04-10") # 8 days
|
|
t_end = make_task("End", "2026-04-21", "2026-04-22")
|
|
|
|
deps = [
|
|
make_dep(t_start.id, t_long.id),
|
|
make_dep(t_start.id, t_short.id),
|
|
make_dep(t_long.id, t_end.id),
|
|
make_dep(t_short.id, t_end.id),
|
|
]
|
|
|
|
result = compute_cpm([t_start, t_long, t_short, t_end], deps)
|
|
assert isinstance(result, tuple)
|
|
cpm_data, duration = result
|
|
|
|
# Long path and start/end should be critical; short path should not
|
|
assert cpm_data[t_long.id]["is_critical"] is True
|
|
assert cpm_data[t_short.id]["is_critical"] is False
|
|
|
|
|
|
def test_cpm_empty_tasks():
|
|
result = compute_cpm([], [])
|
|
assert result == {}
|