| 173 | } |
| 174 | |
| 175 | func 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 | |
| 214 | func testCompressedSetSingle(t *testing.T) { |
| 215 | id := New() |