CompareVals compares two values using the given comparison type. Should be used only in filtering arg1 by comparing with arg2. arg2 is reference Val to which arg1 is compared.
(op string, arg1, arg2 Val)
| 11 | // Should be used only in filtering arg1 by comparing with arg2. |
| 12 | // arg2 is reference Val to which arg1 is compared. |
| 13 | func CompareVals(op string, arg1, arg2 Val) bool { |
| 14 | negateRes := func(b bool, e error) (bool, error) { // reverses result |
| 15 | return !b, e |
| 16 | } |
| 17 | noError := func(b bool, e error) bool { |
| 18 | return b && e == nil |
| 19 | } |
| 20 | switch op { |
| 21 | case "ge": |
| 22 | return noError(negateRes(Less(arg1, arg2))) |
| 23 | case "gt": |
| 24 | return noError(Less(arg2, arg1)) |
| 25 | case "le": |
| 26 | return noError(negateRes(Less(arg2, arg1))) |
| 27 | case "lt": |
| 28 | return noError(Less(arg1, arg2)) |
| 29 | case "eq": |
| 30 | return noError(Equal(arg1, arg2)) |
| 31 | default: |
| 32 | // should have been checked at query level. |
| 33 | x.Fatalf("Unknown ineqType %v", op) |
| 34 | } |
| 35 | return false |
| 36 | } |
| 37 | |
| 38 | // CompareBetween compares if the dst value lie between |
| 39 | // two values val1 and val2(both inclusive). |
no test coverage detected