feat: improve planning engine travel handling, itinerary reordering, and scenario planners
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>
This commit is contained in:
51
SportsTimeTests/Domain/TravelInfoTests.swift
Normal file
51
SportsTimeTests/Domain/TravelInfoTests.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// 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"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user