@@ -19,6 +19,10 @@ var _ = Describe("Glucose", func() {
19
19
Expect (glucose .Mmoll ).To (Equal ("mmol/l" ))
20
20
})
21
21
22
+ It ("has MmolLMinute" , func () {
23
+ Expect (glucose .MmolLMinute ).To (Equal ("mmol/L/minute" ))
24
+ })
25
+
22
26
It ("has MgdL" , func () {
23
27
Expect (glucose .MgdL ).To (Equal ("mg/dL" ))
24
28
})
@@ -27,6 +31,10 @@ var _ = Describe("Glucose", func() {
27
31
Expect (glucose .Mgdl ).To (Equal ("mg/dl" ))
28
32
})
29
33
34
+ It ("has MgdLMinute" , func () {
35
+ Expect (glucose .MgdLMinute ).To (Equal ("mg/dL/minute" ))
36
+ })
37
+
30
38
It ("has MmolLMinimum" , func () {
31
39
Expect (glucose .MmolLMinimum ).To (Equal (0.0 ))
32
40
})
@@ -35,6 +43,14 @@ var _ = Describe("Glucose", func() {
35
43
Expect (glucose .MmolLMaximum ).To (Equal (55.0 ))
36
44
})
37
45
46
+ It ("has MmolLMinuteMinimum" , func () {
47
+ Expect (glucose .MmolLMinuteMinimum ).To (Equal (- 5.5 ))
48
+ })
49
+
50
+ It ("has MmolLMinuteMaximum" , func () {
51
+ Expect (glucose .MmolLMinuteMaximum ).To (Equal (5.5 ))
52
+ })
53
+
38
54
It ("has MgdLMinimum" , func () {
39
55
Expect (glucose .MgdLMinimum ).To (Equal (0.0 ))
40
56
})
@@ -43,6 +59,14 @@ var _ = Describe("Glucose", func() {
43
59
Expect (glucose .MgdLMaximum ).To (Equal (1000.0 ))
44
60
})
45
61
62
+ It ("has MgdLMinuteMinimum" , func () {
63
+ Expect (glucose .MgdLMinuteMinimum ).To (Equal (- 100.0 ))
64
+ })
65
+
66
+ It ("has MgdLMinuteMaximum" , func () {
67
+ Expect (glucose .MgdLMinuteMaximum ).To (Equal (100.0 ))
68
+ })
69
+
46
70
It ("has MmolLToMgdLConversionFactor" , func () {
47
71
Expect (glucose .MmolLToMgdLConversionFactor ).To (Equal (18.01559 ))
48
72
})
@@ -57,6 +81,12 @@ var _ = Describe("Glucose", func() {
57
81
})
58
82
})
59
83
84
+ Context ("RateUnits" , func () {
85
+ It ("returns the expected units" , func () {
86
+ Expect (glucose .RateUnits ()).To (ConsistOf ("mmol/L/minute" , "mg/dL/minute" ))
87
+ })
88
+ })
89
+
60
90
DescribeTable ("ValueRangeForUnits" ,
61
91
func (units * string , expectedLower float64 , expectedUpper float64 ) {
62
92
actualLower , actualUpper := glucose .ValueRangeForUnits (units )
@@ -125,28 +155,87 @@ var _ = Describe("Glucose", func() {
125
155
}
126
156
})
127
157
})
158
+
128
159
Context ("NormalizeValueForUnitsWithFullPrecision" , func () {
129
160
DescribeTable ("given value and units" ,
130
161
func (value * float64 , units * string , expectedValue * float64 ) {
131
162
actualValue := glucose .NormalizeValueForUnitsWithFullPrecision (value , units )
132
- if expectedValue == nil {
133
- Expect (actualValue ).To (BeNil ())
134
- } else {
135
- Expect (actualValue ).ToNot (BeNil ())
136
- Expect (* actualValue ).To (Equal (* expectedValue ))
137
- }
163
+ Expect (actualValue ).To (Equal (expectedValue ))
138
164
},
139
165
Entry ("returns nil for nil value" , nil , pointer .FromString ("mmol/L" ), nil ),
140
166
Entry ("returns unchanged value for nil units" , pointer .FromFloat64 (10.0 ), nil , pointer .FromFloat64 (10.0 )),
141
167
Entry ("returns unchanged value for unknown units" , pointer .FromFloat64 (10.0 ), pointer .FromString ("unknown" ), pointer .FromFloat64 (10.0 )),
142
168
Entry ("returns unchanged value for mmol/L units" , pointer .FromFloat64 (10.0 ), pointer .FromString ("mmol/L" ), pointer .FromFloat64 (10.0 )),
143
169
Entry ("returns unchanged value for mmol/l units" , pointer .FromFloat64 (10.0 ), pointer .FromString ("mmol/l" ), pointer .FromFloat64 (10.0 )),
144
-
145
170
Entry ("returns converted value for mg/dL units" , pointer .FromFloat64 (140.0 ), pointer .FromString ("mg/dL" ), pointer .FromFloat64 (7.771047187463747 )),
146
171
Entry ("returns converted value for mg/dL units" , pointer .FromFloat64 (100.0 ), pointer .FromString ("mg/dL" ), pointer .FromFloat64 (5.550747991045533 )),
147
172
Entry ("returns converted value for mg/dl units" , pointer .FromFloat64 (80.0 ), pointer .FromString ("mg/dl" ), pointer .FromFloat64 (4.440598392836427 )),
148
173
Entry ("returns converted value for mg/dl units" , pointer .FromFloat64 (69.0 ), pointer .FromString ("mg/dl" ), pointer .FromFloat64 (3.830016113821418 )),
149
174
Entry ("returns converted value for mg/dl units" , pointer .FromFloat64 (50.0 ), pointer .FromString ("mg/dl" ), pointer .FromFloat64 (2.7753739955227665 )),
150
175
)
151
176
})
177
+
178
+ DescribeTable ("ValueRangeForRateUnits" ,
179
+ func (rateUnits * string , expectedLower float64 , expectedUpper float64 ) {
180
+ actualLower , actualUpper := glucose .ValueRangeForRateUnits (rateUnits )
181
+ Expect (actualLower ).To (Equal (expectedLower ))
182
+ Expect (actualUpper ).To (Equal (expectedUpper ))
183
+ },
184
+ Entry ("returns no range for nil" , nil , - math .MaxFloat64 , math .MaxFloat64 ),
185
+ Entry ("returns no range for unknown units" , pointer .FromString ("unknown" ), - math .MaxFloat64 , math .MaxFloat64 ),
186
+ Entry ("returns expected range for mmol/L/minute units" , pointer .FromString ("mmol/L/minute" ), - 5.5 , 5.5 ),
187
+ Entry ("returns expected range for mg/dL/minute units" , pointer .FromString ("mg/dL/minute" ), - 100.0 , 100.0 ),
188
+ )
189
+
190
+ DescribeTable ("NormalizeRateUnits" ,
191
+ func (rateUnits * string , expectedRateUnits * string ) {
192
+ actualRateUnits := glucose .NormalizeRateUnits (rateUnits )
193
+ if expectedRateUnits == nil {
194
+ Expect (actualRateUnits ).To (BeNil ())
195
+ } else {
196
+ Expect (actualRateUnits ).ToNot (BeNil ())
197
+ Expect (* actualRateUnits ).To (Equal (* expectedRateUnits ))
198
+ }
199
+ },
200
+ Entry ("returns nil for nil" , nil , nil ),
201
+ Entry ("returns unchanged units for unknown units" , pointer .FromString ("unknown" ), pointer .FromString ("unknown" )),
202
+ Entry ("returns mmol/L/minute for mmol/L/minute" , pointer .FromString ("mmol/L/minute" ), pointer .FromString ("mmol/L/minute" )),
203
+ Entry ("returns mmol/L/minute for mg/dL/minute" , pointer .FromString ("mg/dL/minute" ), pointer .FromString ("mmol/L/minute" )),
204
+ )
205
+
206
+ Context ("NormalizeValueForRateUnits" , func () {
207
+ DescribeTable ("given value and units" ,
208
+ func (value * float64 , rateUnits * string , expectedValue * float64 ) {
209
+ actualValue := glucose .NormalizeValueForRateUnits (value , rateUnits )
210
+ if expectedValue == nil {
211
+ Expect (actualValue ).To (BeNil ())
212
+ } else {
213
+ Expect (actualValue ).ToNot (BeNil ())
214
+ Expect (* actualValue ).To (Equal (* expectedValue ))
215
+ }
216
+ },
217
+
218
+ Entry ("returns nil for nil value" , nil , pointer .FromString ("mmol/L/minute" ), nil ),
219
+ Entry ("returns unchanged value for nil units" , pointer .FromFloat64 (1.0 ), nil , pointer .FromFloat64 (1.0 )),
220
+ Entry ("returns unchanged value for unknown units" , pointer .FromFloat64 (1.0 ), pointer .FromString ("unknown" ), pointer .FromFloat64 (1.0 )),
221
+ Entry ("returns unchanged value for mmol/L/minute units" , pointer .FromFloat64 (1.0 ), pointer .FromString ("mmol/L/minute" ), pointer .FromFloat64 (1.0 )),
222
+ Entry ("returns converted value for mg/dL/minute units" , pointer .FromFloat64 (18.0 ), pointer .FromString ("mg/dL/minute" ), pointer .FromFloat64 (0.99913 )),
223
+ )
224
+
225
+ It ("properly normalizes a range of mmol/L/minute values" , func () {
226
+ for value := glucose .MmolLMinuteMinimum ; value <= glucose .MmolLMinuteMaximum ; value += 0.1 {
227
+ normalizedValue := glucose .NormalizeValueForRateUnits (pointer .FromFloat64 (float64 (value )), pointer .FromString ("mmol/L/minute" ))
228
+ Expect (normalizedValue ).ToNot (BeNil ())
229
+ Expect (* normalizedValue ).To (Equal (value ))
230
+ }
231
+ })
232
+
233
+ It ("properly normalizes a range of mg/dL/minute values" , func () {
234
+ for value := int (glucose .MgdLMinuteMinimum ); value <= int (glucose .MgdLMinuteMaximum ); value ++ {
235
+ normalizedValue := glucose .NormalizeValueForRateUnits (pointer .FromFloat64 (float64 (value )), pointer .FromString ("mg/dL/minute" ))
236
+ Expect (normalizedValue ).ToNot (BeNil ())
237
+ Expect (int (* normalizedValue * 18.01559 + math .Copysign (0.5 , float64 (value )))).To (Equal (value ))
238
+ }
239
+ })
240
+ })
152
241
})
0 commit comments