Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional test coverage around suspend threshold behavior #603

Merged
merged 1 commit into from
Oct 7, 2017
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