diff --git a/DoseMathTests/DoseMathTests.swift b/DoseMathTests/DoseMathTests.swift index 9123bd5cbd..e28f2fd4cf 100644 --- a/DoseMathTests/DoseMathTests.swift +++ b/DoseMathTests/DoseMathTests.swift @@ -573,6 +573,52 @@ class RecommendBolusTests: XCTestCase { } } + func testStartBelowSuspendThresholdEndHigh() { + // 60 - 200 mg/dL + let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high") + + let dose = glucose.recommendedBolus( + to: glucoseTargetRange, + at: glucose.first!.startDate, + suspendThreshold: HKQuantity(unit: .milligramsPerDeciliter(), doubleValue: 70), + sensitivity: insulinSensitivitySchedule, + model: insulinModel, + pendingInsulin: 0, + maxBolus: maxBolus + ) + + XCTAssertEqual(0, dose.amount) + + if case BolusRecommendationNotice.glucoseBelowSuspendThreshold(let glucose) = dose.notice! { + XCTAssertEqual(glucose.quantity.doubleValue(for: .milligramsPerDeciliter()), 60) + } else { + XCTFail("Expected currentGlucoseBelowTarget, but got \(dose.notice!)") + } + } + + func testStartLowNoSuspendThresholdEndHigh() { + // 60 - 200 mg/dL + let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high") + + let dose = glucose.recommendedBolus( + to: glucoseTargetRange, + at: glucose.first!.startDate, + suspendThreshold: nil, // Expected to default to 90 + sensitivity: insulinSensitivitySchedule, + model: insulinModel, + pendingInsulin: 0, + maxBolus: maxBolus + ) + + XCTAssertEqual(0, dose.amount) + + if case BolusRecommendationNotice.glucoseBelowSuspendThreshold(let glucose) = dose.notice! { + XCTAssertEqual(glucose.quantity.doubleValue(for: .milligramsPerDeciliter()), 60) + } else { + XCTFail("Expected currentGlucoseBelowTarget, but got \(dose.notice!)") + } + } + func testDroppingBelowRangeThenRising() { let glucose = loadGlucoseValueFixture("recommend_temp_basal_dropping_then_rising")