Skip to content

Commit 3d8f7d4

Browse files
committed
Add test for get_loop_recommendations and fix helper function import
- Added test coverage for get_loop_recommendations function - Fixed helpers.get_bytes_from_json import issue in api.py - Started addressing platform-specific type compatibility issues - Still working on LoopAlgorithm type mismatch in getDynamicCarbsOnBoard
1 parent 6693372 commit 3d8f7d4

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

Sources/LoopAlgorithmToPython/LoopAlgorithmToPython.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ struct AlgorithmFactory {
3232
static func createScheduleValue(startDate: Date, endDate: Date, value: Double, unit: String) -> AbsoluteScheduleValue<AlgorithmValue> {
3333
#if os(Linux) || os(Windows)
3434
// Linux wants the raw Double
35-
return AbsoluteScheduleValue<Double>(startDate: startDate, endDate: endDate, value: value)
35+
return AbsoluteScheduleValue<AlgorithmValue>(startDate: startDate, endDate: endDate, value: value)
3636
#else
3737
// Mac wants the LoopQuantity object
3838
let quantity = LoopQuantity(unit: LoopUnit(from: unit), doubleValue: value)
39-
return AbsoluteScheduleValue<LoopQuantity>(startDate: startDate, endDate: endDate, value: quantity)
39+
return AbsoluteScheduleValue<AlgorithmValue>(startDate: startDate, endDate: endDate, value: quantity)
4040
#endif
4141
}
4242
}
@@ -438,14 +438,9 @@ public func getDynamicCarbsOnBoard(jsonData: UnsafePointer<Int8>?) -> Double {
438438
let startDate = dateFormatter.date(from: input.inputICE[0].startAt)!
439439
let endDate = dateFormatter.date(from: input.inputICE.last!.startAt)!
440440

441-
// Use the factory to get the right type for the current OS
442-
let carbRatio: [AbsoluteScheduleValue<AlgorithmValue>] = [
443-
AlgorithmFactory.createScheduleValue(startDate: startDate, endDate: endDate, value: input.carbRatio, unit: "g/U")
444-
]
445-
446-
let isf: [AbsoluteScheduleValue<AlgorithmValue>] = [
447-
AlgorithmFactory.createScheduleValue(startDate: startDate, endDate: endDate, value: input.sensitivity, unit: "mg/dL/U")
448-
]
441+
// Create schedule values with Double values as expected by the function
442+
let carbRatio = [AbsoluteScheduleValue(startDate: startDate, endDate: endDate, value: input.carbRatio)]
443+
let isf = [AbsoluteScheduleValue(startDate: startDate, endDate: endDate, value: input.sensitivity)]
449444

450445
let statuses = [carbEntries[0]].map(
451446
to: inputICE,

loop_to_python_api/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_active_insulin(json_file):
143143
return swift_lib.getActiveInsulin(json_bytes)
144144

145145
def get_loop_recommendations(json_file, len=72):
146-
json_bytes = get_bytes_from_json(json_file)
146+
json_bytes = helpers.get_bytes_from_json(json_file)
147147

148148
swift_lib.getLoopRecommendations.argtypes = [ctypes.c_char_p]
149149
swift_lib.getLoopRecommendations.restype = ctypes.c_char_p

python_tests/tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
get_glucose_effect_velocity_and_dates,
1111
get_active_carbs,
1212
get_active_insulin,
13+
get_loop_recommendations,
1314
percent_absorption_at_percent_time,
1415
piecewise_linear_percent_rate_at_percent_time,
1516
linear_percent_rate_at_percent_time,
@@ -122,6 +123,12 @@ def test_get_dynamic_carbs_on_board():
122123
assert isinstance(dynamic_carbs_on_board, float)
123124

124125

126+
def test_get_loop_recommendations():
127+
loop_algorithm_input = get_loop_algorithm_input()
128+
loop_recommendations = get_loop_recommendations(loop_algorithm_input)
129+
assert isinstance(loop_recommendations, str)
130+
131+
125132
def test_insulin_percent_effect_remaining():
126133
# Test with typical rapid-acting insulin parameters
127134
result = insulin_percent_effect_remaining(

0 commit comments

Comments
 (0)