---
phase: 08-dag-system-tdd
type: execute
---
TDD for GameDAGRouter edge cases and anchor game validation.
Purpose: Ensure the DAG routing algorithm handles boundary conditions correctly before testing at scale.
Output: Comprehensive edge case test suite for GameDAGRouter, with code fixes if tests fail.
~/.claude/get-shit-done/workflows/execute-phase.md
./summary.md
~/.claude/get-shit-done/references/tdd.md
@.planning/PROJECT.md
@.planning/ROADMAP.md
@SportsTime/Planning/Engine/GameDAGRouter.swift
@SportsTimeTests/ScenarioBPlannerTests.swift
Task 1: Create GameDAGRouterTests with edge case tests
SportsTimeTests/GameDAGRouterTests.swift
Create a new test file using Swift Testing framework (@Test attributes, #expect assertions).
Include test helpers:
- makeStadium(id:city:lat:lon:) with default coordinates spread across US
- makeGame(id:stadiumId:startTime:) with default sport/teams
- date(_:) helper for "yyyy-MM-dd HH:mm" parsing
Write RED tests for these edge cases:
1. Empty games array → returns empty routes
2. Single game → returns [[game]] (unless anchor mismatch)
3. Single game with non-matching anchor → returns []
4. Two games, chronological and feasible → returns route containing both
5. Two games, chronological but infeasible (too far) → returns two separate single-game routes
6. Two games, reverse chronological (second before first) → returns two separate single-game routes
7. Three games where only pairs are feasible → returns all valid pairs/singles
8. Anchor game filtering: routes missing anchors are excluded
9. Repeat cities OFF: routes with same city twice are excluded
10. Repeat cities ON: routes with same city twice are included
Run tests expecting failures for any code gaps:
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
All edge case tests exist and execute (RED or GREEN)
GameDAGRouterTests.swift contains 10+ edge case tests using Swift Testing framework
Task 2: Fix any failing edge case tests
SportsTime/Planning/Engine/GameDAGRouter.swift
Run the edge case tests. For any failures:
1. Identify the exact assertion that fails
2. Trace the code path in GameDAGRouter.swift
3. Fix the logic bug (do NOT modify the test - tests define correctness)
4. Re-run until GREEN
Common fix areas:
- Edge case handling in findRoutes() lines 101-120
- canTransition() feasibility logic lines 463-507
- Anchor filtering logic lines 181-184
Do NOT change test expectations. If a test fails, the code is wrong.
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
All tests pass
All 10+ edge case tests pass (GREEN)
Task 3: Add canTransition boundary tests
SportsTimeTests/GameDAGRouterTests.swift
Add tests for canTransition edge cases via findRoutes() behavior:
1. Same stadium, same day, 4 hours apart → transition feasible
2. Different stadium, 1000 miles apart, same day → infeasible (not enough driving time)
3. Different stadium, 1000 miles apart, 2 days apart → feasible (enough driving days)
4. Different stadium, 100 miles apart, 4 hours available → feasible
5. Different stadium, 100 miles apart, 1 hour available → infeasible (need 3hr buffer after game)
6. Game end buffer: 3hr buffer after game end before departure
7. Arrival buffer: 1hr buffer before next game start
These test the canTransition() logic indirectly through findRoutes() results.
```bash
xcodebuild -project SportsTime.xcodeproj -scheme SportsTime -destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' -only-testing:SportsTimeTests/GameDAGRouterTests test
```
All tests pass
7 additional boundary tests pass (17+ total tests)
Before declaring phase complete:
- [ ] `xcodebuild test` for GameDAGRouterTests passes with 17+ tests
- [ ] All edge cases documented in test names
- [ ] No tests were modified to pass (code was fixed instead)
- [ ] Existing tests in other test files still pass
- All tasks completed
- All verification checks pass
- 17+ edge case tests for GameDAGRouter
- TDD discipline maintained (tests define correctness)