MCPcopy
hub / github.com/segmentio/ksuid / testCompressedSetDuplicates

Function testCompressedSetDuplicates

set_test.go:175–212  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

173}
174
175func testCompressedSetDuplicates(t *testing.T) {
176 sequence := Sequence{Seed: New()}
177
178 ksuids := [1000]KSUID{}
179 for i := range ksuids[:10] {
180 ksuids[i], _ = sequence.Next() // exercise dedupe on the id range code path
181 }
182 for i := range ksuids[10:] {
183 ksuids[i+10] = New()
184 }
185 for i := 1; i < len(ksuids); i += 4 {
186 ksuids[i] = ksuids[i-1] // generate many dupes
187 }
188
189 miss := make(map[KSUID]struct{})
190 uniq := make(map[KSUID]struct{})
191
192 for _, id := range ksuids {
193 miss[id] = struct{}{}
194 }
195
196 set := Compress(ksuids[:]...)
197
198 for it := set.Iter(); it.Next(); {
199 if _, dupe := uniq[it.KSUID]; dupe {
200 t.Errorf("duplicate id found in compressed set: %s", it.KSUID)
201 }
202 uniq[it.KSUID] = struct{}{}
203 delete(miss, it.KSUID)
204 }
205
206 if len(miss) != 0 {
207 t.Error("some ids were not found in the compressed set:")
208 for id := range miss {
209 t.Log(id)
210 }
211 }
212}
213
214func testCompressedSetSingle(t *testing.T) {
215 id := New()

Callers

nothing calls this directly

Calls 5

NextMethod · 0.95
NewFunction · 0.85
CompressFunction · 0.85
IterMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…