forked from asafschers/goscore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpe_predicate_test.go
57 lines (52 loc) · 1.63 KB
/
simpe_predicate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package goscore_test
import (
"encoding/xml"
"github.com/asafschers/goscore"
"testing"
)
var simplePredicateTests = []struct {
predicate []byte
features map[string]interface{}
expected bool
}{
{[]byte(`<SimplePredicate field="f33" operator="equal" value="18.85"/>`),
map[string]interface{}{"f33": 18.850},
true},
{[]byte(`<SimplePredicate field="f33" operator="lessOrEqual" value="18.85"/>`),
map[string]interface{}{"f33": 18.84},
true},
{[]byte(`<SimplePredicate field="f33" operator="lessOrEqual" value="18.85"/>`),
map[string]interface{}{"f33": 18.86},
false},
{[]byte(`<SimplePredicate field="f33" operator="lessOrEqual" value="18.85"/>`),
map[string]interface{}{"f33": "18.84"},
true},
{[]byte(`<SimplePredicate field="f33" operator="isMissing" value="18.85"/>`),
map[string]interface{}{"f33": 18.86},
false},
{[]byte(`<SimplePredicate field="f33" operator="isMissing" value="18.85"/>`),
map[string]interface{}{},
true},
{[]byte(`<SimplePredicate field="f33" operator="isMissing" value="18.85"/>`),
map[string]interface{}{"f33": nil},
true},
{[]byte(`<SimplePredicate field="f33" operator="isMissing" value="18.85"/>`),
map[string]interface{}{"f33": ""},
true},
}
func TestSimplePredicate(t *testing.T) {
for _, tt := range simplePredicateTests {
var predicate goscore.SimplePredicate
xml.Unmarshal(tt.predicate, &predicate)
actual := predicate.True(tt.features)
if actual != tt.expected {
t.Errorf("Predicate: %s %s %s, Feature value : %s, expected %t, actual %t",
predicate.Field,
predicate.Operator,
predicate.Value,
tt.features[predicate.Field],
tt.expected,
actual)
}
}
}