Trends: chart key shows average price per station + descriptor footer

Legend rows now show each station's average over the days shown
in brackets (pence; signed +X.Xp in vs-cheapest mode, matching the
list-row deltas). Footer under the key explains the figure per mode.
averagePence helper (nil for empty series) + 3 tests; -showTrends
becomes a permanent QA hook like -showKeySheet.
This commit is contained in:
FuelBoard Contributor
2026-08-16 10:39:49 +01:00
parent 9aea478317
commit 430006be94
5 changed files with 71 additions and 0 deletions
@@ -164,6 +164,29 @@ final class FuelHistoryTests: XCTestCase {
XCTAssertEqual(pruned.count, days.count)
}
// MARK: Chart-key average
func testAveragePenceEmptyIsNil() {
XCTAssertNil(FuelHistoryStore.averagePence([]))
}
func testAveragePenceSinglePoint() {
let d = FuelHistoryStore.date(fromDay: "2026-08-15")!
XCTAssertEqual(FuelHistoryStore.averagePence([PricePoint(date: d, pence: 156.7)]), 156.7)
}
func testAveragePenceMultiplePoints() {
let d1 = FuelHistoryStore.date(fromDay: "2026-08-15")!
let d2 = FuelHistoryStore.date(fromDay: "2026-08-16")!
// (153.9 + 156.7) / 2 = 155.3 exact in binary? 153.9+156.7=310.6, /2=155.3
let avg = FuelHistoryStore.averagePence([
PricePoint(date: d1, pence: 153.9),
PricePoint(date: d2, pence: 156.7),
])
XCTAssertNotNil(avg)
XCTAssertEqual(avg!, 155.3, accuracy: 0.0001)
}
// MARK: Mirror URLs
func testHistoryFileURLKeepsBaseLastSegment() {