Skip to content

Commit 0fe7775

Browse files
committed
Cleanup DataManagerTestType, and rename to DosingTestScenario to clarify it as scoping a reusable testing scenario and not a specific test
1 parent feb306b commit 0fe7775

File tree

5 files changed

+44
-60
lines changed

5 files changed

+44
-60
lines changed

LoopTests/Managers/LoopDataManagerDosingTests.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,9 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
458458
}
459459

460460
func testAutoBolusMaxIOBClamping() {
461-
/// `maximumBolus` is set to clamp the automatic dose
461+
/// `maxBolus` is set to clamp the automatic dose
462462
/// Autobolus without clamping: 0.65 U. Clamped recommendation: 0.2 U.
463-
setUp(for: .autoBolusIOBClamping, maxBolus: 5)
463+
setUp(for: .highAndRisingWithCOB, maxBolus: 5, dosingStrategy: .automaticBolus)
464464

465465
// This sets up dose rounding
466466
let delegate = MockDelegate()
@@ -479,7 +479,7 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
479479
updateGroup.wait()
480480

481481
XCTAssertEqual(recommendedBolus!, 0.5, accuracy: 0.01)
482-
XCTAssertEqual(insulinOnBoard?.value, 9.47)
482+
XCTAssertEqual(insulinOnBoard?.value, 9.5)
483483

484484
/// Set the `maximumBolus` to 10U so there's no clamping
485485
updateGroup.enter()
@@ -492,13 +492,13 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
492492
updateGroup.wait()
493493

494494
XCTAssertEqual(recommendedBolus!, 0.65, accuracy: 0.01)
495-
XCTAssertEqual(insulinOnBoard?.value, 9.47)
495+
XCTAssertEqual(insulinOnBoard?.value, 9.5)
496496
}
497497

498498
func testTempBasalMaxIOBClamping() {
499499
/// `maximumBolus` is set to 5U to clamp max IOB at 10U
500-
/// Without clamping: 4.25 U/hr. Clamped recommendation: 1.25 U/hr.
501-
setUp(for: .tempBasalIOBClamping, maxBolus: 5)
500+
/// Without clamping: 4.25 U/hr. Clamped recommendation: 2.0 U/hr.
501+
setUp(for: .highAndRisingWithCOB, maxBolus: 5)
502502

503503
// This sets up dose rounding
504504
let delegate = MockDelegate()
@@ -516,8 +516,8 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
516516
}
517517
updateGroup.wait()
518518

519-
XCTAssertEqual(recommendedBasal!.unitsPerHour, 1.25, accuracy: 0.01)
520-
XCTAssertEqual(insulinOnBoard?.value, 9.87)
519+
XCTAssertEqual(recommendedBasal!.unitsPerHour, 2.0, accuracy: 0.01)
520+
XCTAssertEqual(insulinOnBoard?.value, 9.5)
521521

522522
/// Set the `maximumBolus` to 10U so there's no clamping
523523
updateGroup.enter()
@@ -530,7 +530,7 @@ class LoopDataManagerDosingTests: LoopDataManagerTests {
530530
updateGroup.wait()
531531

532532
XCTAssertEqual(recommendedBasal!.unitsPerHour, 4.25, accuracy: 0.01)
533-
XCTAssertEqual(insulinOnBoard?.value, 9.87)
533+
XCTAssertEqual(insulinOnBoard?.value, 9.5)
534534
}
535535

536536
}

LoopTests/Managers/LoopDataManagerTests.swift

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,13 @@ import LoopKit
1414

1515
public typealias JSONDictionary = [String: Any]
1616

17-
enum DataManagerTestType {
17+
enum DosingTestScenario {
1818
case flatAndStable
1919
case highAndStable
2020
case highAndRisingWithCOB
2121
case lowAndFallingWithCOB
2222
case lowWithLowTreatment
2323
case highAndFalling
24-
/// uses fixtures for .highAndRisingWithCOB with a low max bolus and dosing set to autobolus
25-
case autoBolusIOBClamping
26-
case tempBasalIOBClamping
27-
}
28-
29-
extension DataManagerTestType {
30-
var dosingStrategy: AutomaticDosingStrategy {
31-
switch self {
32-
case .autoBolusIOBClamping:
33-
return .automaticBolus
34-
default:
35-
return .tempBasalOnly
36-
}
37-
}
3824
}
3925

4026
extension TimeZone {
@@ -88,7 +74,12 @@ class LoopDataManagerTests: XCTestCase {
8874
var automaticDosingStatus: AutomaticDosingStatus!
8975
var loopDataManager: LoopDataManager!
9076

91-
func setUp(for test: DataManagerTestType, basalDeliveryState: PumpManagerStatus.BasalDeliveryState? = nil, maxBolus: Double = 10, maxBasalRate: Double = 5.0) {
77+
func setUp(for test: DosingTestScenario,
78+
basalDeliveryState: PumpManagerStatus.BasalDeliveryState? = nil,
79+
maxBolus: Double = 10,
80+
maxBasalRate: Double = 5.0,
81+
dosingStrategy: AutomaticDosingStrategy = .tempBasalOnly)
82+
{
9283
let basalRateSchedule = loadBasalRateScheduleFixture("basal_profile")
9384
let carbRatioSchedule = CarbRatioSchedule(
9485
unit: .gram(),
@@ -106,7 +97,7 @@ class LoopDataManagerTests: XCTestCase {
10697
maximumBasalRatePerHour: maxBasalRate,
10798
maximumBolus: maxBolus,
10899
suspendThreshold: suspendThreshold,
109-
automaticDosingStrategy: test.dosingStrategy
100+
automaticDosingStrategy: dosingStrategy
110101
)
111102

112103
let doseStore = MockDoseStore(for: test)

LoopTests/Mock Stores/MockCarbStore.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import LoopKit
1111
@testable import Loop
1212

1313
class MockCarbStore: CarbStoreProtocol {
14-
init(for test: DataManagerTestType = .flatAndStable) {
15-
self.testType = test // The store returns different effect values based on the test type
14+
init(for scenario: DosingTestScenario = .flatAndStable) {
15+
self.scenario = scenario // The store returns different effect values based on the scenario
1616
}
1717

18-
var testType: DataManagerTestType
18+
var scenario: DosingTestScenario
1919

2020
var sampleType: HKSampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier.dietaryCarbohydrates)!
2121

@@ -119,12 +119,12 @@ extension MockCarbStore {
119119
}
120120

121121
var fixtureToLoad: String {
122-
switch testType {
122+
switch scenario {
123123
case .flatAndStable:
124124
return "flat_and_stable_carb_effect"
125125
case .highAndStable:
126126
return "high_and_stable_carb_effect"
127-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
127+
case .highAndRisingWithCOB:
128128
return "high_and_rising_with_cob_carb_effect"
129129
case .lowAndFallingWithCOB:
130130
return "low_and_falling_carb_effect"

LoopTests/Mock Stores/MockDoseStore.swift

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import LoopKit
1212

1313
class MockDoseStore: DoseStoreProtocol {
1414

15-
init(for test: DataManagerTestType = .flatAndStable) {
16-
self.testType = test // The store returns different effect values based on the test type
17-
self.pumpEventQueryAfterDate = MockDoseStore.currentDate(for: test)
18-
self.lastAddedPumpData = MockDoseStore.currentDate(for: test)
15+
init(for scenario: DosingTestScenario = .flatAndStable) {
16+
self.scenario = scenario // The store returns different effect values based on the scenario
17+
self.pumpEventQueryAfterDate = MockDoseStore.currentDate(for: scenario)
18+
self.lastAddedPumpData = MockDoseStore.currentDate(for: scenario)
1919
}
2020

2121
static let dateFormatter = ISO8601DateFormatter.localTimeDate()
2222

23-
var testType: DataManagerTestType
23+
var scenario: DosingTestScenario
2424

2525
var basalProfileApplyingOverrideHistory: BasalRateSchedule?
2626

@@ -50,7 +50,7 @@ class MockDoseStore: DoseStoreProtocol {
5050
var lastReservoirValue: ReservoirValue?
5151

5252
var lastAddedPumpData: Date
53-
53+
5454
func addPumpEvents(_ events: [NewPumpEvent], lastReconciliation: Date?, completion: @escaping (DoseStore.DoseStoreError?) -> Void) {
5555
completion(nil)
5656
}
@@ -60,14 +60,7 @@ class MockDoseStore: DoseStoreProtocol {
6060
}
6161

6262
func insulinOnBoard(at date: Date, completion: @escaping (DoseStoreResult<InsulinValue>) -> Void) {
63-
switch testType {
64-
case .highAndRisingWithCOB, .flatAndStable, .highAndFalling, .highAndStable, .lowAndFallingWithCOB, .lowWithLowTreatment:
65-
completion(.success(.init(startDate: MockDoseStore.currentDate(for: testType), value: 9.5)))
66-
case .autoBolusIOBClamping:
67-
completion(.success(.init(startDate: MockDoseStore.currentDate(for: testType), value: 9.47)))
68-
case .tempBasalIOBClamping:
69-
completion(.success(.init(startDate: MockDoseStore.currentDate(for: testType), value: 9.87)))
70-
}
63+
completion(.success(.init(startDate: MockDoseStore.currentDate(for: scenario), value: 9.5)))
7164
}
7265

7366
func generateDiagnosticReport(_ completion: @escaping (String) -> Void) {
@@ -113,13 +106,13 @@ class MockDoseStore: DoseStoreProtocol {
113106
}))
114107
}
115108

116-
static func currentDate(for testType: DataManagerTestType) -> Date {
109+
static func currentDate(for testType: DosingTestScenario) -> Date {
117110
switch testType {
118111
case .flatAndStable:
119112
return dateFormatter.date(from: "2020-08-11T20:45:02")!
120113
case .highAndStable:
121114
return dateFormatter.date(from: "2020-08-12T12:39:22")!
122-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
115+
case .highAndRisingWithCOB:
123116
return dateFormatter.date(from: "2020-08-11T21:48:17")!
124117
case .lowAndFallingWithCOB:
125118
return dateFormatter.date(from: "2020-08-11T22:06:06")!
@@ -142,12 +135,12 @@ extension MockDoseStore {
142135
}
143136

144137
var fixtureToLoad: String {
145-
switch testType {
138+
switch scenario {
146139
case .flatAndStable:
147140
return "flat_and_stable_insulin_effect"
148141
case .highAndStable:
149142
return "high_and_stable_insulin_effect"
150-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
143+
case .highAndRisingWithCOB:
151144
return "high_and_rising_with_cob_insulin_effect"
152145
case .lowAndFallingWithCOB:
153146
return "low_and_falling_insulin_effect"

LoopTests/Mock Stores/MockGlucoseStore.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import LoopKit
1212

1313
class MockGlucoseStore: GlucoseStoreProtocol {
1414

15-
init(for test: DataManagerTestType = .flatAndStable) {
16-
self.testType = test // The store returns different effect values based on the test type
15+
init(for scenario: DosingTestScenario = .flatAndStable) {
16+
self.scenario = scenario // The store returns different effect values based on the scenario
1717
}
1818

1919
let dateFormatter = ISO8601DateFormatter.localTimeDate()
2020

21-
var testType: DataManagerTestType
21+
var scenario: DosingTestScenario
2222

2323
var latestGlucose: GlucoseSampleValue? {
2424
return StoredGlucoseSample(
@@ -107,12 +107,12 @@ extension MockGlucoseStore {
107107
}
108108

109109
var counteractionEffectToLoad: String {
110-
switch testType {
110+
switch scenario {
111111
case .flatAndStable:
112112
return "flat_and_stable_counteraction_effect"
113113
case .highAndStable:
114114
return "high_and_stable_counteraction_effect"
115-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
115+
case .highAndRisingWithCOB:
116116
return "high_and_rising_with_cob_counteraction_effect"
117117
case .lowAndFallingWithCOB:
118118
return "low_and_falling_counteraction_effect"
@@ -124,12 +124,12 @@ extension MockGlucoseStore {
124124
}
125125

126126
var momentumEffectToLoad: String {
127-
switch testType {
127+
switch scenario {
128128
case .flatAndStable:
129129
return "flat_and_stable_momentum_effect"
130130
case .highAndStable:
131131
return "high_and_stable_momentum_effect"
132-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
132+
case .highAndRisingWithCOB:
133133
return "high_and_rising_with_cob_momentum_effect"
134134
case .lowAndFallingWithCOB:
135135
return "low_and_falling_momentum_effect"
@@ -141,12 +141,12 @@ extension MockGlucoseStore {
141141
}
142142

143143
var glucoseStartDate: Date {
144-
switch testType {
144+
switch scenario {
145145
case .flatAndStable:
146146
return dateFormatter.date(from: "2020-08-11T20:45:02")!
147147
case .highAndStable:
148148
return dateFormatter.date(from: "2020-08-12T12:39:22")!
149-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
149+
case .highAndRisingWithCOB:
150150
return dateFormatter.date(from: "2020-08-11T21:48:17")!
151151
case .lowAndFallingWithCOB:
152152
return dateFormatter.date(from: "2020-08-11T22:06:06")!
@@ -158,12 +158,12 @@ extension MockGlucoseStore {
158158
}
159159

160160
var latestGlucoseValue: Double {
161-
switch testType {
161+
switch scenario {
162162
case .flatAndStable:
163163
return 123.42849966275706
164164
case .highAndStable:
165165
return 200.0
166-
case .highAndRisingWithCOB, .autoBolusIOBClamping, .tempBasalIOBClamping:
166+
case .highAndRisingWithCOB:
167167
return 129.93174411197853
168168
case .lowAndFallingWithCOB:
169169
return 75.10768374646841

0 commit comments

Comments
 (0)