Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions DoseMathTests/DoseMathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down