@@ -7,6 +7,47 @@ import org.junit.Assert.*
77import org.junit.Test
88
99class MealInsulinProjectionTest {
10+ @Test fun intervalDeliveryWithoutDoseUnitsCannotDisappearFromInventory () {
11+ for (type in listOf (" temp_basal" , " treatment" , " carbs" , " unknown" )) {
12+ for (field in listOf (" rate" , " absolute" , " percent" , " relative" )) {
13+ for (value in listOf (" 0" , " 1.5" , " -100" , " NaN" , " unknown" )) {
14+ val event = TherapyEvent (now - 60_000L , type,
15+ mapOf (field to value, " duration" to " 30" ), sourceRowId = " interval-1" )
16+ val result = engine().projectMealTimingInsulin(glucose, listOf (event), 60 )
17+ assertEquals(" $type /$field /$value " , 1 , result.unsupportedEventCount)
18+ assertTrue(result.unsupportedReasons.contains(MealInsulinInventoryIssue .NON_INSTANT_OR_AMBIGUOUS_DELIVERY ))
19+ assertThrows(IllegalArgumentException ::class .java) { result.requireUsableInventory() }
20+ }
21+ }
22+ }
23+ }
24+
25+ @Test fun deliveryOnlyTypesRequireEvidenceEvenWhenFieldsAreMissing () {
26+ for (type in listOf (" basal" , " Temp Basal" , " tempBasal" , " temporary_basal" , " basal_rate" ,
27+ " Extended Bolus" , " combo_bolus" , " pump_suspend" , " pump_resume" )) {
28+ val event = TherapyEvent (now - 60_000L , type, emptyMap(), sourceRowId = " interval-1" )
29+ assertEquals(type, 1 , engine().projectMealTimingInsulin(glucose, listOf (event), 60 ).unsupportedEventCount)
30+ }
31+ }
32+
33+ @Test fun oldOrDuplicateRateOnlyRecordsRemainUnsupportedRatherThanExpiredOrAbsent () {
34+ val old = TherapyEvent (now - 48 * 60 * 60_000L , " treatment" ,
35+ mapOf (" absolute" to " 0" , " duration" to " 2880" ), sourceRowId = " interval-1" )
36+ val result = engine().projectMealTimingInsulin(glucose, listOf (old, old), 60 )
37+ assertEquals(2 , result.unsupportedEventCount)
38+ assertTrue(result.unsupportedReasons.contains(MealInsulinInventoryIssue .DUPLICATE_OR_EMPTY_IDENTITY ))
39+ }
40+
41+ @Test fun nullIntervalFieldsAndOrdinaryFoodOrExerciseDurationDoNotInventInsulin () {
42+ for (type in listOf (" carbs" , " exercise" , " note" )) {
43+ val event = TherapyEvent (now, type, mapOf (" duration" to " 30" , " units" to " g" ,
44+ " rate" to " null" , " absolute" to " null" , " percent" to " null" , " relative" to " null" ))
45+ val result = engine().projectMealTimingInsulin(glucose, listOf (event), 60 )
46+ assertEquals(0 , result.unsupportedEventCount)
47+ assertEquals(0 , result.modeledEventCount)
48+ }
49+ }
50+
1051 @Test fun insulinPayloadCannotDisappearBehindAnUnrecognizedEventType () {
1152 for (type in listOf (" treatment" , " meal" , " note" , " unknown" )) {
1253 val event = bolus.copy(type = type, payload = mapOf (" insulin" to " 2" ))
0 commit comments