Stabilize unit and UI tests for SportsTime
This commit is contained in:
@@ -24,7 +24,7 @@ struct GameDAGRouterTests {
|
||||
private let laCoord = CLLocationCoordinate2D(latitude: 34.0141, longitude: -118.2879)
|
||||
private let seattleCoord = CLLocationCoordinate2D(latitude: 47.5914, longitude: -122.3316)
|
||||
|
||||
private let calendar = Calendar.current
|
||||
private let calendar = TestClock.calendar
|
||||
|
||||
// MARK: - Specification Tests: Edge Cases
|
||||
|
||||
@@ -40,7 +40,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: single game with no anchors returns single-game route")
|
||||
func findRoutes_singleGame_noAnchors_returnsSingleRoute() {
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: Date())
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: TestClock.now)
|
||||
|
||||
let routes = GameDAGRouter.findRoutes(
|
||||
games: [game],
|
||||
@@ -55,7 +55,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: single game matching anchor returns single-game route")
|
||||
func findRoutes_singleGame_matchingAnchor_returnsSingleRoute() {
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: Date())
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: TestClock.now)
|
||||
|
||||
let routes = GameDAGRouter.findRoutes(
|
||||
games: [game],
|
||||
@@ -70,7 +70,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: single game not matching anchor returns empty")
|
||||
func findRoutes_singleGame_notMatchingAnchor_returnsEmpty() {
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: Date())
|
||||
let (game, stadium) = makeGameAndStadium(city: "New York", date: TestClock.now)
|
||||
|
||||
let routes = GameDAGRouter.findRoutes(
|
||||
games: [game],
|
||||
@@ -86,7 +86,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: two feasible games returns combined route")
|
||||
func findRoutes_twoFeasibleGames_returnsCombinedRoute() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Date = calendar.date(bySettingHour: 13, minute: 0, second: 0, of: today)!
|
||||
let game2Date = calendar.date(bySettingHour: 19, minute: 0, second: 0, of: today)!
|
||||
|
||||
@@ -112,7 +112,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: two infeasible same-day games returns separate routes when no anchors")
|
||||
func findRoutes_twoInfeasibleGames_noAnchors_returnsSeparateRoutes() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Date = calendar.date(bySettingHour: 13, minute: 0, second: 0, of: today)!
|
||||
let game2Date = calendar.date(bySettingHour: 15, minute: 0, second: 0, of: today)! // Only 2 hours later
|
||||
|
||||
@@ -135,7 +135,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: two infeasible games with both as anchors returns empty")
|
||||
func findRoutes_twoInfeasibleGames_bothAnchors_returnsEmpty() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Date = calendar.date(bySettingHour: 13, minute: 0, second: 0, of: today)!
|
||||
let game2Date = calendar.date(bySettingHour: 15, minute: 0, second: 0, of: today)!
|
||||
|
||||
@@ -158,7 +158,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: routes contain all anchor games")
|
||||
func findRoutes_routesContainAllAnchors() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let dates = (0..<5).map { dayOffset in
|
||||
calendar.date(byAdding: .day, value: dayOffset, to: today)!
|
||||
}
|
||||
@@ -199,7 +199,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: allowRepeatCities=false excludes routes with duplicate cities")
|
||||
func findRoutes_disallowRepeatCities_excludesDuplicates() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let dates = (0..<3).map { dayOffset in
|
||||
calendar.date(byAdding: .day, value: dayOffset, to: today)!
|
||||
}
|
||||
@@ -228,7 +228,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: allowRepeatCities=true allows routes with duplicate cities")
|
||||
func findRoutes_allowRepeatCities_allowsDuplicates() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let dates = (0..<3).map { dayOffset in
|
||||
calendar.date(byAdding: .day, value: dayOffset, to: today)!
|
||||
}
|
||||
@@ -270,7 +270,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: all routes are chronologically ordered")
|
||||
func findRoutes_allRoutesChronological() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let dates = (0..<5).map { dayOffset in
|
||||
calendar.date(byAdding: .day, value: dayOffset, to: today)!
|
||||
}
|
||||
@@ -307,7 +307,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: respects maxDailyDrivingHours for same-day games")
|
||||
func findRoutes_respectsSameDayDrivingLimit() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Time = calendar.date(bySettingHour: 13, minute: 0, second: 0, of: today)!
|
||||
let game2Time = calendar.date(bySettingHour: 20, minute: 0, second: 0, of: today)!
|
||||
|
||||
@@ -331,7 +331,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: multi-day trips allow longer total driving")
|
||||
func findRoutes_multiDayTrips_allowLongerDriving() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Date = today
|
||||
let game2Date = calendar.date(byAdding: .day, value: 2, to: today)! // 2 days later
|
||||
|
||||
@@ -355,7 +355,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("findRoutes: anchor routes can span gaps larger than 5 days")
|
||||
func findRoutes_anchorRoutesAllowLongDateGaps() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let day0 = today
|
||||
let day1 = calendar.date(byAdding: .day, value: 1, to: today)!
|
||||
let day8 = calendar.date(byAdding: .day, value: 8, to: today)!
|
||||
@@ -387,7 +387,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("Property: route count never exceeds maxOptions (75)")
|
||||
func property_routeCountNeverExceedsMax() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
// Create many games to stress test
|
||||
var games: [Game] = []
|
||||
@@ -413,7 +413,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("Property: all routes satisfy constraints")
|
||||
func property_allRoutesSatisfyConstraints() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let dates = (0..<5).map { calendar.date(byAdding: .day, value: $0, to: today)! }
|
||||
|
||||
let gamesAndStadiums = [
|
||||
@@ -469,7 +469,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("Edge: games at same stadium always feasible")
|
||||
func edge_sameStadium_alwaysFeasible() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Time = calendar.date(bySettingHour: 13, minute: 0, second: 0, of: today)!
|
||||
let game2Time = calendar.date(bySettingHour: 19, minute: 0, second: 0, of: today)! // Doubleheader
|
||||
|
||||
@@ -489,7 +489,7 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("Edge: games out of order are sorted chronologically")
|
||||
func edge_unsortedGames_areSorted() {
|
||||
let today = calendar.startOfDay(for: Date())
|
||||
let today = calendar.startOfDay(for: TestClock.now)
|
||||
let game1Date = calendar.date(byAdding: .day, value: 2, to: today)!
|
||||
let game2Date = today
|
||||
let game3Date = calendar.date(byAdding: .day, value: 1, to: today)!
|
||||
@@ -517,8 +517,8 @@ struct GameDAGRouterTests {
|
||||
|
||||
@Test("Edge: missing stadium for game is handled gracefully")
|
||||
func edge_missingStadium_handledGracefully() {
|
||||
let (game1, stadium1) = makeGameAndStadium(city: "New York", date: Date(), coord: nycCoord)
|
||||
let game2 = makeGame(stadiumId: "nonexistent-stadium", date: Date().addingTimeInterval(86400))
|
||||
let (game1, stadium1) = makeGameAndStadium(city: "New York", date: TestClock.now, coord: nycCoord)
|
||||
let game2 = makeGame(stadiumId: "nonexistent-stadium", date: TestClock.now.addingTimeInterval(86400))
|
||||
|
||||
// Only provide stadium for game1
|
||||
let stadiums = [stadium1.id: stadium1]
|
||||
|
||||
Reference in New Issue
Block a user