Add TravelInfo initializers and city normalization helpers to fix repeat city-pair disambiguation. Improve drag-and-drop reordering with segment index tracking and source-row-aware zone calculation. Enhance all five scenario planners with better next-day departure handling and travel segment placement. Add comprehensive tests across all planners. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.6 KiB
Swift
52 lines
1.6 KiB
Swift
//
|
|
// 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"))
|
|
}
|
|
}
|
|
|