Skip to content

Commit d939229

Browse files
authored
Merge pull request #603 from LoopKit/test-suspend-threshold
Additional test coverage around suspend threshold behavior
2 parents c58dd8a + f50e1e1 commit d939229

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

DoseMathTests/DoseMathTests.swift

+46
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,52 @@ class RecommendBolusTests: XCTestCase {
573573
}
574574
}
575575

576+
func testStartBelowSuspendThresholdEndHigh() {
577+
// 60 - 200 mg/dL
578+
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high")
579+
580+
let dose = glucose.recommendedBolus(
581+
to: glucoseTargetRange,
582+
at: glucose.first!.startDate,
583+
suspendThreshold: HKQuantity(unit: .milligramsPerDeciliter(), doubleValue: 70),
584+
sensitivity: insulinSensitivitySchedule,
585+
model: insulinModel,
586+
pendingInsulin: 0,
587+
maxBolus: maxBolus
588+
)
589+
590+
XCTAssertEqual(0, dose.amount)
591+
592+
if case BolusRecommendationNotice.glucoseBelowSuspendThreshold(let glucose) = dose.notice! {
593+
XCTAssertEqual(glucose.quantity.doubleValue(for: .milligramsPerDeciliter()), 60)
594+
} else {
595+
XCTFail("Expected currentGlucoseBelowTarget, but got \(dose.notice!)")
596+
}
597+
}
598+
599+
func testStartLowNoSuspendThresholdEndHigh() {
600+
// 60 - 200 mg/dL
601+
let glucose = loadGlucoseValueFixture("recommend_temp_basal_start_low_end_high")
602+
603+
let dose = glucose.recommendedBolus(
604+
to: glucoseTargetRange,
605+
at: glucose.first!.startDate,
606+
suspendThreshold: nil, // Expected to default to 90
607+
sensitivity: insulinSensitivitySchedule,
608+
model: insulinModel,
609+
pendingInsulin: 0,
610+
maxBolus: maxBolus
611+
)
612+
613+
XCTAssertEqual(0, dose.amount)
614+
615+
if case BolusRecommendationNotice.glucoseBelowSuspendThreshold(let glucose) = dose.notice! {
616+
XCTAssertEqual(glucose.quantity.doubleValue(for: .milligramsPerDeciliter()), 60)
617+
} else {
618+
XCTFail("Expected currentGlucoseBelowTarget, but got \(dose.notice!)")
619+
}
620+
}
621+
576622
func testDroppingBelowRangeThenRising() {
577623
let glucose = loadGlucoseValueFixture("recommend_temp_basal_dropping_then_rising")
578624

0 commit comments

Comments
 (0)