-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrange_input_filter_test.go
172 lines (130 loc) · 5.01 KB
/
range_input_filter_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package scopes_test
import (
. "gopkg.in/check.v1"
"launchpad.net/go-unityscopes/v2"
)
func (s *S) TestRangeInputFilter(c *C) {
filter1 := scopes.NewRangeInputFilter("f1", nil, nil, "start_prefix", "start_postfix", "end_prefix", "end_postfix", "central")
c.Check("f1", Equals, filter1.Id)
c.Check(nil, Equals, filter1.DefaultStartValue)
c.Check(nil, Equals, filter1.DefaultEndValue)
c.Check("start_prefix", Equals, filter1.StartPrefixLabel)
c.Check("start_postfix", Equals, filter1.StartPostfixLabel)
c.Check("end_prefix", Equals, filter1.EndPrefixLabel)
c.Check("end_postfix", Equals, filter1.EndPostfixLabel)
c.Check("central", Equals, filter1.CentralLabel)
// check the selection
fstate := make(scopes.FilterState)
start, found := filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found := filter1.EndValue(fstate)
c.Check(found, Equals, false)
// test setting floats
err := filter1.UpdateState(fstate, 10.2, 100.4)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, 10.2)
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, 100.4)
c.Check(found, Equals, true)
// test setting floats with no decimals
err = filter1.UpdateState(fstate, 10.0, 100.0)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, 10.0)
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, 100.0)
c.Check(found, Equals, true)
// test setting mixed floats and integers
err = filter1.UpdateState(fstate, 10, 100.0)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, float64(10))
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, 100.0)
c.Check(found, Equals, true)
// test integers
err = filter1.UpdateState(fstate, 10, 100)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, float64(10))
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, float64(100))
c.Check(found, Equals, true)
// test integer and nil
err = filter1.UpdateState(fstate, nil, 100)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, float64(100))
c.Check(found, Equals, true)
// test float and nil
err = filter1.UpdateState(fstate, 10.4, nil)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, 10.4)
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(found, Equals, false)
// test both nil
err = filter1.UpdateState(fstate, nil, nil)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found = filter1.EndValue(fstate)
c.Check(found, Equals, false)
// start greater then end
err = filter1.UpdateState(fstate, 10, 0.6)
c.Check(err, Not(Equals), nil)
c.Check(err.Error(), Equals, "RangeInputFilter::UpdateState(): start_value 10 is greater or equal to end_value 0.6 for filter f1")
start, found = filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found = filter1.EndValue(fstate)
c.Check(found, Equals, false)
// start equals end
err = filter1.UpdateState(fstate, 10, 10.0)
c.Check(err, Not(Equals), nil)
c.Check(err.Error(), Equals, "RangeInputFilter::UpdateState(): start_value 10 is greater or equal to end_value 10 for filter f1")
start, found = filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found = filter1.EndValue(fstate)
c.Check(found, Equals, false)
// bad values
err = filter1.UpdateState(fstate, "", 10.0)
c.Check(err, Not(Equals), nil)
c.Check(err.Error(), Equals, "RangeInputFilter:UpdateState: Bad type for start value. Valid types are int float64 and nil")
err = filter1.UpdateState(fstate, 1, "")
c.Check(err, Not(Equals), nil)
c.Check(err.Error(), Equals, "RangeInputFilter:UpdateState: Bad type for end value. Valid types are int float64 and nil")
err = filter1.UpdateState(fstate, 1, []int{1, 2})
c.Check(err, Not(Equals), nil)
c.Check(err.Error(), Equals, "RangeInputFilter:UpdateState: Bad type for end value. Valid types are int float64 and nil")
start, found = filter1.StartValue(fstate)
c.Check(found, Equals, false)
end, found = filter1.EndValue(fstate)
c.Check(found, Equals, false)
// try to set values again
err = filter1.UpdateState(fstate, 10, 100)
c.Check(err, IsNil)
start, found = filter1.StartValue(fstate)
c.Check(start, Equals, float64(10))
c.Check(found, Equals, true)
end, found = filter1.EndValue(fstate)
c.Check(end, Equals, float64(100))
c.Check(found, Equals, true)
}
func (s *S) TestRangeInputFilterDefaults(c *C) {
filter := scopes.NewRangeInputFilter("f1", 0, 100, "start_prefix", "start_postfix", "end_prefix", "end_postfix", "central")
fstate := make(scopes.FilterState)
start, ok := filter.StartValue(fstate)
c.Check(ok, Equals, true)
c.Check(start, Equals, 0.0)
end, ok := filter.EndValue(fstate)
c.Check(ok, Equals, true)
c.Check(end, Equals, 100.0)
}