Audit and fix 52 test correctness issues across 22 files
Systematic audit of 1,191 tests found tests written to pass rather than verify correctness. Key fixes: Infrastructure: - TestClock: fixed timezone from .current to America/New_York (deterministic) - TestFixtures: added 1.3x road routing factor to match production - ItineraryTestHelpers: real per-city coordinates instead of hardcoded (40,-80) Planning tests: - Added missing Scenario E factory dispatch tests - Tightened 12 loose assertions (>= 1 → == 8.0, > 0 → range checks) - Fixed 4 no-op tests that accepted both success and failure - Fixed wrong repeat-city invariant (was checking same-day, not different-day) - Fixed tautological assertion in missing-stadium edge case Services/Domain/Export tests: - Replaced 4 placeholder tests (#expect(true)) with real assertions - Fixed tautological assertions in POISearchServiceTests - Fixed Chicago coordinate in RegionMapSelectorTests (-89 → -87.6553) - Added sort order verification to ItineraryRowFlatteningTests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,25 @@ struct Phase1A_RoutePreferenceTests {
|
||||
#expect(route[i].startTime <= route[i + 1].startTime)
|
||||
}
|
||||
}
|
||||
|
||||
// Direct should produce lower-mileage first routes than scenic
|
||||
if let directFirst = directRoutes.first, let scenicFirst = scenicRoutes.first {
|
||||
let directMiles = directFirst.compactMap { game -> Double? in
|
||||
guard let idx = directFirst.firstIndex(where: { $0.id == game.id }),
|
||||
idx > 0,
|
||||
let from = stadiums[directFirst[idx - 1].stadiumId],
|
||||
let to = stadiums[game.stadiumId] else { return nil }
|
||||
return TravelEstimator.haversineDistanceMiles(from: from.coordinate, to: to.coordinate) * 1.3
|
||||
}.reduce(0, +)
|
||||
let scenicMiles = scenicFirst.compactMap { game -> Double? in
|
||||
guard let idx = scenicFirst.firstIndex(where: { $0.id == game.id }),
|
||||
idx > 0,
|
||||
let from = stadiums[scenicFirst[idx - 1].stadiumId],
|
||||
let to = stadiums[game.stadiumId] else { return nil }
|
||||
return TravelEstimator.haversineDistanceMiles(from: from.coordinate, to: to.coordinate) * 1.3
|
||||
}.reduce(0, +)
|
||||
#expect(directMiles <= scenicMiles, "Direct first route should have <= mileage than scenic first route")
|
||||
}
|
||||
}
|
||||
|
||||
@Test("findRoutes accepts routePreference parameter for all values")
|
||||
@@ -165,6 +184,9 @@ struct Phase1B_ScenarioERegionTests {
|
||||
let nycTeam = TestFixtures.team(id: "team_nyc", name: "NYC Team", sport: .mlb, city: "New York")
|
||||
let bosTeam = TestFixtures.team(id: "team_bos", name: "BOS Team", sport: .mlb, city: "Boston")
|
||||
|
||||
// With 2 teams, teamFirstMaxDays = 4. The sliding window needs the game
|
||||
// span to be wide enough so a 4-day window can contain both games.
|
||||
// Space games 3 days apart so a window from June 1 to June 5 covers both.
|
||||
let game1 = TestFixtures.game(
|
||||
id: "nyc_home", city: "New York",
|
||||
dateTime: baseDate,
|
||||
@@ -173,7 +195,7 @@ struct Phase1B_ScenarioERegionTests {
|
||||
)
|
||||
let game2 = TestFixtures.game(
|
||||
id: "bos_home", city: "Boston",
|
||||
dateTime: TestClock.calendar.date(byAdding: .day, value: 1, to: baseDate)!,
|
||||
dateTime: TestClock.calendar.date(byAdding: .day, value: 3, to: baseDate)!,
|
||||
homeTeamId: "team_bos",
|
||||
stadiumId: "stadium_mlb_boston"
|
||||
)
|
||||
@@ -199,13 +221,11 @@ struct Phase1B_ScenarioERegionTests {
|
||||
let result = planner.plan(request: request)
|
||||
|
||||
// Should succeed with both nearby East Coast teams.
|
||||
// Failure is also OK if driving constraints prevent it.
|
||||
switch result {
|
||||
case .success(let options):
|
||||
#expect(!options.isEmpty, "Should find routes for NYC + Boston")
|
||||
case .failure:
|
||||
break // Acceptable — driving constraints may prevent a valid route
|
||||
guard case .success(let options) = result else {
|
||||
Issue.record("Expected .success for NYC + Boston (nearby East Coast teams), got \(result)")
|
||||
return
|
||||
}
|
||||
#expect(!options.isEmpty, "Should find routes for NYC + Boston")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,15 +608,17 @@ struct Phase2D_ExclusionWarningTests {
|
||||
// If all routes had repeat cities, failure is also acceptable
|
||||
return
|
||||
}
|
||||
// Every returned route must have unique cities per calendar day
|
||||
for option in options {
|
||||
let calendar = Calendar.current
|
||||
var cityDays: Set<String> = []
|
||||
// Group stops by city, check no city appears on multiple calendar days
|
||||
var cityDays: [String: Set<Date>] = [:]
|
||||
let calendar = TestClock.calendar
|
||||
for stop in option.stops {
|
||||
let day = calendar.startOfDay(for: stop.arrivalDate)
|
||||
let key = "\(stop.city.lowercased())_\(day.timeIntervalSince1970)"
|
||||
#expect(!cityDays.contains(key), "Route should not visit \(stop.city) on the same day twice")
|
||||
cityDays.insert(key)
|
||||
let city = stop.city.lowercased()
|
||||
cityDays[city, default: []].insert(day)
|
||||
}
|
||||
for (city, days) in cityDays {
|
||||
#expect(days.count <= 1, "City '\(city)' appears on \(days.count) different days — repeat city violation")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user