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") + } }