Stabilize unit and UI tests for SportsTime
This commit is contained in:
@@ -40,8 +40,8 @@ struct ScenarioEPlannerTests {
|
||||
// With 2 teams, window duration = 4 days.
|
||||
// The window algorithm checks: windowEnd <= latestGameDay + 1
|
||||
// So with games on day 1 and day 4: latestDay=4, windowEnd=5 <= day 5 (4+1) - valid!
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -102,7 +102,7 @@ struct ScenarioEPlannerTests {
|
||||
@Test("generateValidWindows: window with only 2 of 3 teams excluded")
|
||||
func generateValidWindows_windowMissingTeam_excluded() {
|
||||
// Setup: 3 teams selected, but games are spread so no single window covers all 3
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -168,7 +168,7 @@ struct ScenarioEPlannerTests {
|
||||
@Test("generateValidWindows: empty season returns empty")
|
||||
func generateValidWindows_emptySeason_returnsEmpty() {
|
||||
// Setup: No games available
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let prefs = TripPreferences(
|
||||
planningMode: .teamFirst,
|
||||
@@ -204,8 +204,8 @@ struct ScenarioEPlannerTests {
|
||||
@Test("generateValidWindows: sampling works when more than 50 windows")
|
||||
func generateValidWindows_manyWindows_samplesProperly() {
|
||||
// Setup: Create many overlapping games so there are >50 valid windows
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -278,8 +278,8 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: returns PlanningResult with routes")
|
||||
func plan_validRequest_returnsPlanningResultWithRoutes() {
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -339,8 +339,8 @@ struct ScenarioEPlannerTests {
|
||||
@Test("plan: all routes include all selected teams")
|
||||
func plan_allRoutesIncludeAllSelectedTeams() {
|
||||
// Use just 2 teams for a simpler, more reliable test
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -408,8 +408,8 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: falls back when earliest per-team anchors are infeasible")
|
||||
func plan_fallbackWhenEarliestAnchorsInfeasible() {
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let chicagoStadium = makeStadium(id: "chi", city: "Chicago", coordinate: chicagoCoord)
|
||||
@@ -477,8 +477,8 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: keeps date-distinct options even when city order is identical")
|
||||
func plan_keepsDistinctGameSetsWithSameCityOrder() {
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -548,7 +548,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: routes sorted by duration ascending")
|
||||
func plan_routesSortedByDurationAscending() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -621,7 +621,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: respects max driving time constraint")
|
||||
func plan_respectsMaxDrivingTimeConstraint() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
// NYC and LA are ~40 hours apart by car
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
@@ -681,7 +681,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: teams with no overlapping games returns graceful error")
|
||||
func plan_noOverlappingGames_returnsGracefulError() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -735,7 +735,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: single team selected returns validation error")
|
||||
func plan_singleTeamSelected_returnsValidationError() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
|
||||
@@ -777,7 +777,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: no teams selected returns validation error")
|
||||
func plan_noTeamsSelected_returnsValidationError() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let prefs = TripPreferences(
|
||||
planningMode: .teamFirst,
|
||||
@@ -810,8 +810,8 @@ struct ScenarioEPlannerTests {
|
||||
@Test("plan: teams in same city treated as separate stops")
|
||||
func plan_teamsInSameCity_treatedAsSeparateStops() {
|
||||
// Setup: Yankees and Mets both play in NYC but at different stadiums
|
||||
let calendar = Calendar.current
|
||||
let baseDate = calendar.startOfDay(for: Date())
|
||||
let calendar = TestClock.calendar
|
||||
let baseDate = calendar.startOfDay(for: TestClock.now)
|
||||
|
||||
let yankeeStadiumCoord = CLLocationCoordinate2D(latitude: 40.8296, longitude: -73.9262)
|
||||
let citiFieldCoord = CLLocationCoordinate2D(latitude: 40.7571, longitude: -73.8458)
|
||||
@@ -879,7 +879,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("plan: team with no home games returns error")
|
||||
func plan_teamWithNoHomeGames_returnsError() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
|
||||
@@ -942,7 +942,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("Invariant: maximum 10 results returned")
|
||||
func invariant_maximum10ResultsReturned() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
@@ -996,7 +996,7 @@ struct ScenarioEPlannerTests {
|
||||
|
||||
@Test("Invariant: all routes contain home games from all selected teams")
|
||||
func invariant_allRoutesContainAllSelectedTeams() {
|
||||
let baseDate = Date()
|
||||
let baseDate = TestClock.now
|
||||
|
||||
let nycStadium = makeStadium(id: "nyc", city: "New York", coordinate: nycCoord)
|
||||
let bostonStadium = makeStadium(id: "boston", city: "Boston", coordinate: bostonCoord)
|
||||
|
||||
Reference in New Issue
Block a user