MCPcopy
hub / github.com/syncthing/syncthing / TestCompare

Function TestCompare

lib/protocol/vector_test.go:161–390  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func TestCompare(t *testing.T) {
162 testcases := []struct {
163 a, b Vector
164 r Ordering
165 }{
166 // Empty vectors are identical
167 {Vector{}, Vector{}, Equal},
168 {Vector{}, Vector{Counters: []Counter{{ID: 42, Value: 0}}}, Equal},
169 {Vector{Counters: []Counter{{ID: 42, Value: 0}}}, Vector{}, Equal},
170
171 // Zero is the implied value for a missing Counter
172 {
173 Vector{Counters: []Counter{{ID: 42, Value: 0}}},
174 Vector{Counters: []Counter{{ID: 77, Value: 0}}},
175 Equal,
176 },
177
178 // Equal vectors are equal
179 {
180 Vector{Counters: []Counter{{ID: 42, Value: 33}}},
181 Vector{Counters: []Counter{{ID: 42, Value: 33}}},
182 Equal,
183 },
184 {
185 Vector{Counters: []Counter{{ID: 42, Value: 33}, {ID: 77, Value: 24}}},
186 Vector{Counters: []Counter{{ID: 42, Value: 33}, {ID: 77, Value: 24}}},
187 Equal,
188 },
189
190 // These a-vectors are all greater than the b-vector
191 {
192 Vector{Counters: []Counter{{ID: 42, Value: 1}}},
193 Vector{},
194 Greater,
195 },
196 {
197 Vector{Counters: []Counter{{ID: 0, Value: 1}}},
198 Vector{Counters: []Counter{{ID: 0, Value: 0}}},
199 Greater,
200 },
201 {
202 Vector{Counters: []Counter{{ID: 42, Value: 1}}},
203 Vector{Counters: []Counter{{ID: 42, Value: 0}}},
204 Greater,
205 },
206 {
207 Vector{Counters: []Counter{{ID: math.MaxUint64, Value: 1}}},
208 Vector{Counters: []Counter{{ID: math.MaxUint64, Value: 0}}},
209 Greater,
210 },
211 {
212 Vector{Counters: []Counter{{ID: 0, Value: math.MaxUint64}}},
213 Vector{Counters: []Counter{{ID: 0, Value: 0}}},
214 Greater,
215 },
216 {
217 Vector{Counters: []Counter{{ID: 42, Value: math.MaxUint64}}},
218 Vector{Counters: []Counter{{ID: 42, Value: 0}}},

Callers

nothing calls this directly

Calls 5

ConcurrentMethod · 0.80
GreaterEqualMethod · 0.80
LesserEqualMethod · 0.80
CompareMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected