-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit_rule_test.go
88 lines (80 loc) · 1.64 KB
/
unit_rule_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package rule
import (
"testing"
)
func TestUnitRule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rs1rule := NewUnitRuler(func(c Context) (bool, error) {
c0, err := c.PluckInt("c0")
if err != nil {
return false, err
}
return c0 == 12, nil
})
res, err := rs1rule.Rule(Context(ctx))
if err != nil || !res {
panic("fail")
}
}
func TestComparatorGTERule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", gte, 10)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}
func TestComparatorNERule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", neq, 10)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}
func TestComparatorEQRule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", eq, 12)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}
func TestComparatorGTRule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", gt, 1)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}
func TestComparatorLTRule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", lt, 1000)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}
func TestComparatorLTERule(t *testing.T) {
ctx := NewContext(map[string]interface{}{
"c0": 12,
})
rule, _ := NewComparatorRule("c0", lte, 12)
res, err := rule.Rule(ctx)
if err != nil || !res {
panic(err)
}
}