Browse Source

Merge pull request #1283 from nightscout/oref-swift-fix-carb-ratio

Update minimum carb ratio in oref-swift to 1
Deniz Cengiz 16 hours ago
parent
commit
7bd8dfa8b9

+ 1 - 1
Trio/Sources/APS/OpenAPSSwift/Profile/Carbs.swift

@@ -19,7 +19,7 @@ struct Carbs {
         }
 
         // Check for invalid values
-        if currentRatio < 3 || currentRatio > 150 {
+        if currentRatio < 1 || currentRatio > 150 {
             warning(.openAPS, "Warning: carbRatio of \(currentRatio) out of bounds.")
             return nil
         }

+ 13 - 1
TrioTests/OpenAPSSwiftTests/ProfileCarbsTests.swift

@@ -35,11 +35,23 @@ import Testing
         #expect(ratio == 1) // 12 grams per exchange
     }
 
+    @Test("should allow ratios of 1") func allowLowRatios() async throws {
+        let schedule = CarbRatios(
+            units: .grams,
+            schedule: [
+                CarbRatioEntry(start: "00:00:00", offset: 0, ratio: 1)
+            ]
+        )
+        let now = Calendar.current.date(from: DateComponents(year: 2025, month: 1, day: 26, hour: 2))!
+        let ratio = Carbs.carbRatioLookup(carbRatio: schedule, now: now)
+        #expect(ratio == 1)
+    }
+
     @Test("should reject invalid ratios") func rejectInvalidRatios() async throws {
         let invalidSchedule = CarbRatios(
             units: .grams,
             schedule: [
-                CarbRatioEntry(start: "00:00:00", offset: 0, ratio: 2),
+                CarbRatioEntry(start: "00:00:00", offset: 0, ratio: 0.5),
                 CarbRatioEntry(start: "03:00:00", offset: 180, ratio: 15)
             ]
         )