// // TravelInfoTests.swift // SportsTimeTests // // Tests for canonical TravelInfo construction and city matching. // import Testing @testable import SportsTime @Suite("TravelInfo") struct TravelInfoTests { private func makeSegment(from: String, to: String) -> TravelSegment { TravelSegment( fromLocation: LocationInput(name: from), toLocation: LocationInput(name: to), travelMode: .drive, distanceMeters: 120_000, durationSeconds: 7_200 ) } @Test("init(segment:) derives canonical city pair and metrics") func initFromSegment() { let segment = makeSegment(from: "Detroit", to: "Chicago") let info = TravelInfo(segment: segment, segmentIndex: 2) #expect(info.fromCity == "Detroit") #expect(info.toCity == "Chicago") #expect(info.segmentIndex == 2) #expect(info.distanceMeters == segment.distanceMeters) #expect(info.durationSeconds == segment.durationSeconds) } @Test("normalizeCityName trims and lowercases") func normalizeCityName() { #expect(TravelInfo.normalizeCityName(" New York ") == "new york") } @Test("matches(segment:) uses normalized city comparison") func matchesSegment() { let segment = makeSegment(from: "Seattle", to: "Portland") let info = TravelInfo(fromCity: " seattle ", toCity: "PORTLAND ") #expect(info.matches(segment: segment)) #expect(info.matches(from: "SEATTLE", to: "portland")) #expect(!info.matches(from: "Seattle", to: "San Francisco")) } }