-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add configurable CGM sensor lifetime for sensor change alarm #579
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // LoopFollow | ||
| // SensorAgeConditionTests.swift | ||
|
|
||
| @testable import LoopFollow | ||
| import Testing | ||
|
|
||
| struct SensorAgeConditionTests { | ||
| let cond = SensorAgeCondition() | ||
|
|
||
| // MARK: - 10-day lifetime (default) | ||
|
|
||
| @Test("fires when within threshold hours of 10-day expiry") | ||
| func firesNear10DayExpiry() { | ||
| let alarm = Alarm.sensorChange(threshold: 12, lifetimeDays: 10) | ||
| // Sensor inserted 9 days and 13 hours ago → 11 hours until 10-day mark → within 12-hour window | ||
| let insertTime = Date().addingTimeInterval(-9 * 86400 - 13 * 3600).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| @Test("does NOT fire when far from 10-day expiry") | ||
| func doesNotFireEarly() { | ||
| let alarm = Alarm.sensorChange(threshold: 12, lifetimeDays: 10) | ||
| // Sensor inserted 8 days ago → 2 days until 10-day mark → outside 12-hour window | ||
| let insertTime = Date().addingTimeInterval(-8 * 86400).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(!cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| // MARK: - 15-day lifetime | ||
|
|
||
| @Test("fires when within threshold hours of 15-day expiry") | ||
| func firesNear15DayExpiry() { | ||
| let alarm = Alarm.sensorChange(threshold: 12, lifetimeDays: 15) | ||
| // Sensor inserted 14 days and 13 hours ago → 11 hours until 15-day mark | ||
| let insertTime = Date().addingTimeInterval(-14 * 86400 - 13 * 3600).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| @Test("does NOT fire at day 10 when lifetime is 15 days") | ||
| func doesNotFireAtDay10With15DayLifetime() { | ||
| let alarm = Alarm.sensorChange(threshold: 12, lifetimeDays: 15) | ||
| // Sensor inserted 10 days ago → 5 days until 15-day mark → should NOT fire | ||
| let insertTime = Date().addingTimeInterval(-10 * 86400).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(!cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| // MARK: - Edge cases | ||
|
|
||
| @Test("does NOT fire when sageInsertTime is nil") | ||
| func ignoresMissingSensor() { | ||
| let alarm = Alarm.sensorChange(threshold: 12) | ||
| let data = AlarmData.withSensorInsertTime(nil) | ||
| #expect(!cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| @Test("does NOT fire when sageInsertTime is zero (no sensor data)") | ||
| func ignoresZeroInsertTime() { | ||
| let alarm = Alarm.sensorChange(threshold: 12) | ||
| let data = AlarmData.withSensorInsertTime(0) | ||
| #expect(!cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| @Test("does NOT fire when threshold is nil") | ||
| func ignoresNilThreshold() { | ||
| let alarm = Alarm.sensorChange(threshold: nil) | ||
| let insertTime = Date().addingTimeInterval(-11 * 86400).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(!cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
|
|
||
| @Test("defaults to 10-day lifetime when sensorLifetimeDays is nil") | ||
| func defaultsTo10Days() { | ||
| let alarm = Alarm.sensorChange(threshold: 12, lifetimeDays: nil) | ||
| // Sensor inserted 9 days and 13 hours ago → within 12-hour window of 10-day mark | ||
| let insertTime = Date().addingTimeInterval(-9 * 86400 - 13 * 3600).timeIntervalSince1970 | ||
| let data = AlarmData.withSensorInsertTime(insertTime) | ||
| #expect(cond.evaluate(alarm: alarm, data: data, now: .init())) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.