From 13be6ffca5c4a24219969976d5bc293ed6cc199d Mon Sep 17 00:00:00 2001 From: Trey t Date: Sat, 10 Jan 2026 11:58:51 -0600 Subject: [PATCH] test(08-02): add performance tests with large datasets Added 4 performance tests with 1K, 5K, 10K games to validate DAG algorithm scalability. Tests currently failing (RED phase). Tests: - 1K games: <2s expected - 5K games: <10s expected - 10K games: <30s expected - 10K games: memory stability Helper generateLargeDataset() creates realistic test data with distributed stadiums and games across time spans. Co-Authored-By: Claude Sonnet 4.5 --- SportsTimeTests/GameDAGRouterTests.swift | 109 +++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/SportsTimeTests/GameDAGRouterTests.swift b/SportsTimeTests/GameDAGRouterTests.swift index 60782c5..2f4ad03 100644 --- a/SportsTimeTests/GameDAGRouterTests.swift +++ b/SportsTimeTests/GameDAGRouterTests.swift @@ -534,4 +534,113 @@ struct GameDAGRouterTests { #expect(routeWithBoth != nil, "4 hours available (with 1hr arrival buffer) should be feasible") } + + // MARK: - Performance Tests + + /// Generates a large dataset of games and stadiums for performance testing. + /// Games are distributed across stadiums and days to simulate realistic data. + private func generateLargeDataset( + gameCount: Int, + stadiumCount: Int, + daysSpan: Int + ) -> (games: [Game], stadiums: [UUID: Stadium]) { + // Create stadiums distributed across the US (roughly) + var stadiums: [UUID: Stadium] = [:] + let baseDate = date("2026-06-01 19:00") + + for i in 0.. 0, "Should return routes") + #expect(elapsed < .seconds(2), "Should complete within 2 seconds, actual: \(elapsed)") + } + + @Test("Performance: 5000 games completes in under 10 seconds") + func performance_5000Games_CompletesInTime() { + let (games, stadiums) = generateLargeDataset(gameCount: 5000, stadiumCount: 100, daysSpan: 60) + + let start = ContinuousClock.now + let routes = GameDAGRouter.findRoutes( + games: games, + stadiums: stadiums, + constraints: .default + ) + let elapsed = start.duration(to: .now) + + #expect(routes.count > 0, "Should return routes") + #expect(elapsed < .seconds(10), "Should complete within 10 seconds, actual: \(elapsed)") + } + + @Test("Performance: 10000 games completes in under 30 seconds") + func performance_10000Games_CompletesInTime() { + let (games, stadiums) = generateLargeDataset(gameCount: 10000, stadiumCount: 150, daysSpan: 90) + + let start = ContinuousClock.now + let routes = GameDAGRouter.findRoutes( + games: games, + stadiums: stadiums, + constraints: .default + ) + let elapsed = start.duration(to: .now) + + #expect(routes.count > 0, "Should return routes") + #expect(elapsed < .seconds(30), "Should complete within 30 seconds, actual: \(elapsed)") + } + + @Test("Performance: 10000 games does not cause memory issues") + func performance_10000Games_NoMemorySpike() { + let (games, stadiums) = generateLargeDataset(gameCount: 10000, stadiumCount: 150, daysSpan: 90) + + // Run the algorithm + let routes = GameDAGRouter.findRoutes( + games: games, + stadiums: stadiums, + constraints: .default + ) + + // Verify routes returned (not OOM) + #expect(routes.count > 0, "Should return routes without memory crash") + #expect(routes.count <= 100, "Should return reasonable number of routes") + } }