@@ -225,14 +225,14 @@ func Test_isNotOneOf_Fail(t *testing.T) {
225
225
assert .Equal (t , expected , result )
226
226
}
227
227
228
- func Test_evaluateNumericcondition_Success (t * testing.T ) {
228
+ func Test_evaluateNumericcondition_Fail (t * testing.T ) {
229
229
expected := false
230
230
result := evaluateNumericCondition (40 , 30.0 , condition {Operator : "LT" , Value : 30.0 })
231
231
232
232
assert .Equal (t , expected , result )
233
233
}
234
234
235
- func Test_evaluateNumericcondition_Fail (t * testing.T ) {
235
+ func Test_evaluateNumericcondition_Success (t * testing.T ) {
236
236
expected := true
237
237
result := evaluateNumericCondition (25 , 30.0 , condition {Operator : "LT" , Value : 30.0 })
238
238
@@ -281,3 +281,45 @@ func Test_isNotNull_attributePresent(t *testing.T) {
281
281
})
282
282
assert .True (t , result )
283
283
}
284
+
285
+ func Test_handles_all_numeric_types (t * testing.T ) {
286
+ condition := condition {Operator : "GT" , Attribute : "powerLevel" , Value : "9000" }
287
+ // Floats
288
+ assert .True (t , condition .matches (Attributes { "powerLevel" : 9001.0 }) )
289
+ assert .False (t , condition .matches (Attributes { "powerLevel" : 9000.0 }) )
290
+ assert .True (t , condition .matches (Attributes { "powerLevel" : float64 (9001 )}) )
291
+ assert .False (t , condition .matches (Attributes { "powerLevel" : float64 (- 9001.0 )}) )
292
+ assert .True (t , condition .matches (Attributes { "powerLevel" : float32 (9001 )}) )
293
+ assert .False (t , condition .matches (Attributes { "powerLevel" : float32 (8999 )}) )
294
+ // Signed Integers
295
+ assert .True (t , condition .matches (Attributes { "powerLevel" : 9001 }) )
296
+ assert .False (t , condition .matches (Attributes { "powerLevel" : 9000 }) )
297
+ assert .False (t , condition .matches (Attributes { "powerLevel" : int8 (1 )}) )
298
+ assert .True (t , condition .matches (Attributes { "powerLevel" : int16 (9001 )}) )
299
+ assert .False (t , condition .matches (Attributes { "powerLevel" : int16 (- 9002 )}) )
300
+ assert .True (t , condition .matches (Attributes { "powerLevel" : int32 (10000 )}) )
301
+ assert .False (t , condition .matches (Attributes { "powerLevel" : int32 (0 )}) )
302
+ assert .True (t , condition .matches (Attributes { "powerLevel" : int64 (9001 )}) )
303
+ assert .False (t , condition .matches (Attributes { "powerLevel" : int64 (8999 )}) )
304
+ // Unsigned Integers
305
+ assert .False (t , condition .matches (Attributes { "powerLevel" : uint8 (1 )}) )
306
+ assert .True (t , condition .matches (Attributes { "powerLevel" : uint16 (9001 )}) )
307
+ assert .False (t , condition .matches (Attributes { "powerLevel" : uint16 (8999 )}) )
308
+ assert .True (t , condition .matches (Attributes { "powerLevel" : uint32 (10000 )}) )
309
+ assert .False (t , condition .matches (Attributes { "powerLevel" : uint32 (0 )}) )
310
+ assert .True (t , condition .matches (Attributes { "powerLevel" : uint64 (9001 )}) )
311
+ assert .False (t , condition .matches (Attributes { "powerLevel" : uint64 (8999 )}) )
312
+ // Strings
313
+ assert .True (t , condition .matches (Attributes { "powerLevel" : "9001" }) )
314
+ assert .True (t , condition .matches (Attributes { "powerLevel" : "9000.1" }) )
315
+ assert .False (t , condition .matches (Attributes { "powerLevel" : "9000" }) )
316
+ assert .False (t , condition .matches (Attributes { "powerLevel" : ".2" }) )
317
+ }
318
+
319
+ func Test_invalid_numeric_types (t * testing.T ) {
320
+ condition := condition {Operator : "GT" , Attribute : "powerLevel" , Value : "9000" }
321
+ assert .False (t , condition .matches (Attributes { "powerLevel" : "empty" }) )
322
+ assert .False (t , condition .matches (Attributes { "powerLevel" : "" }) )
323
+ assert .False (t , condition .matches (Attributes { "powerLevel" : false }) )
324
+ assert .False (t , condition .matches (Attributes { "powerLevel" : true }) )
325
+ }
0 commit comments