Optional Fuel Savings feature (off by default): vehicle MPG in UK imperial gallons, fill amount in pounds or litres, persisted through the existing keychain/app-group store. Ranks the WHOLE station pool by estimated net saving (fuel-price saving at each pump minus the extra return-trip driving cost) using MapKit road distances with a straight-line fallback marked (est.). The closest station with a valid price for the selected fuel is the comparison baseline and is labelled "Closest station"; other rows read "Save £X.XX after travel" / "£X.XX worse off after travel" / "Break even". Labels live in the shared model so they are unit-tested. The TOP badge still marks the cheapest pump price and reads "CHEAPEST" when the list is ranked by net saving. Road routing now prioritises the Worth-the-Drive candidates plus the baseline and merges cache entries instead of replacing them, so far-out stations get real routes rather than permanent straight-line estimates. Numeric fields gain a Done button above the keypad (decimalPad has no Return key); the fill-up control is hidden unless the feature is configured; Favourites shares one session fill amount with the station list. 131 tests.
38 lines
1.3 KiB
Swift
38 lines
1.3 KiB
Swift
import XCTest
|
|
#if SWIFT_PACKAGE
|
|
@testable import FuelBoardShared
|
|
#endif
|
|
|
|
final class FuelSavingsRoutingCacheTests: XCTestCase {
|
|
override func setUp() {
|
|
super.setUp()
|
|
FuelStore.saveRoadDistances(sourceLat: 0, sourceLng: 0, entries: [:])
|
|
}
|
|
|
|
private func station(_ id: String, _ lat: Double, _ lng: Double) -> FuelStation {
|
|
FuelStation(id: id, name: id, brand: "X", address: "", postcode: "", lat: lat, lng: lng, prices: [.e10: 140], priceUpdated: nil)
|
|
}
|
|
|
|
func testJourneyDistanceUsesSeparateOutAndBackRoadRoutes() {
|
|
let s = station("a", 51.5074, -0.1278)
|
|
FuelStore.saveRoadDistances(
|
|
sourceLat: 51.6,
|
|
sourceLng: -0.1,
|
|
entries: ["a": CachedRoadDistance(meters: 3_200, lat: 51.5074, lng: -0.1278, returnMeters: 3_700)]
|
|
)
|
|
|
|
XCTAssertEqual(FuelStore.roadJourneyMeters(for: s, userLat: 51.6, userLng: -0.1), 6_900)
|
|
}
|
|
|
|
func testLegacyOneWayCacheDoublesForJourneyDistance() {
|
|
let s = station("a", 51.5074, -0.1278)
|
|
FuelStore.saveRoadDistances(
|
|
sourceLat: 51.6,
|
|
sourceLng: -0.1,
|
|
entries: ["a": CachedRoadDistance(meters: 3_200, lat: 51.5074, lng: -0.1278)]
|
|
)
|
|
|
|
XCTAssertEqual(FuelStore.roadJourneyMeters(for: s, userLat: 51.6, userLng: -0.1), 6_400)
|
|
}
|
|
}
|