|
15 | 15 | piecewise_linear_percent_rate_at_percent_time, |
16 | 16 | linear_percent_rate_at_percent_time, |
17 | 17 | get_dynamic_carbs_on_board, |
| 18 | + insulin_percent_effect_remaining, |
18 | 19 | ) |
19 | 20 |
|
20 | 21 |
|
@@ -122,3 +123,30 @@ def test_get_dynamic_carbs_on_board(): |
122 | 123 | assert isinstance(dynamic_carbs_on_board, float) |
123 | 124 |
|
124 | 125 |
|
| 126 | +def test_insulin_percent_effect_remaining(): |
| 127 | + # Test with typical rapid-acting insulin parameters |
| 128 | + result = insulin_percent_effect_remaining( |
| 129 | + minutes=60, # 60 minutes after injection |
| 130 | + action_duration=360, # 6 hours total duration |
| 131 | + peak_activity_time=75, # Peak at 75 minutes |
| 132 | + delay=10 # 10 minute delay |
| 133 | + ) |
| 134 | + |
| 135 | + # Basic assertions |
| 136 | + assert isinstance(result, float), "Result should be a float" |
| 137 | + assert 0.0 <= result <= 1.0, f"Result should be between 0.0 and 1.0, got {result}" |
| 138 | + |
| 139 | + # Test edge cases |
| 140 | + # At time 0 (before delay), should have close to 100% effect remaining |
| 141 | + result_start = insulin_percent_effect_remaining(0, 360, 75, 10) |
| 142 | + assert result_start > 0.9, f"At start, should have >90% remaining, got {result_start}" |
| 143 | + |
| 144 | + # At very end of action duration, should have very little effect remaining |
| 145 | + result_end = insulin_percent_effect_remaining(360, 360, 75, 10) |
| 146 | + assert result_end < 0.1, f"At end, should have <10% remaining, got {result_end}" |
| 147 | + |
| 148 | + # At peak time, should have less than 100% but more than end |
| 149 | + result_peak = insulin_percent_effect_remaining(75, 360, 75, 10) |
| 150 | + assert result_end < result_peak < result_start, "Effect should decrease over time" |
| 151 | + |
| 152 | + |
0 commit comments