import XCTest #if SWIFT_PACKAGE @testable import FuelBoardShared #endif /// The Best Value gate's option list. /// /// This one array is the figure behind two user-facing things — the BEST VALUE /// badge on a station row and the proximity alert — so its granularity is a /// setting, not an implementation detail. It was four coarse values (50p, £1, /// £2, £5); these tests pin the 50p step and the £5 ceiling so a later edit /// cannot quietly coarsen it back. final class FuelStoreBestValueThresholdTests: XCTestCase { func testOptionsStepByFiftyPenceUpToFivePounds() { let options = FuelStore.bestValueAlertThresholdOptionsGBP XCTAssertEqual(options, [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]) XCTAssertEqual(options.count, 10) XCTAssertEqual(options.first, 0.5, "the floor is the cheapest worth-the-drive saving offered") XCTAssertEqual(options.last, 5.0, "£5 is the ceiling") } /// The store writes the threshold as a string and, on load, rejects any /// value that is not one of these options — falling back to the £1 default. /// So an option that does not survive `String` → `Double` exactly would /// silently discard the user's choice. Multiples of 0.5 are exactly /// representable in binary, and this keeps them that way. func testEveryOptionSurvivesTheStoresStringRoundTrip() { for option in FuelStore.bestValueAlertThresholdOptionsGBP { XCTAssertEqual(Double(String(option)), option, "£\(option) does not round-trip through the store's string encoding") } } }