MCPcopy
hub / github.com/RoaringBitmap/roaring / TestBitmapExtraCOW

Function TestBitmapExtraCOW

roaringcow_test.go:282–341  ·  view source on GitHub ↗

some extra tests

(t *testing.T)

Source from the content-addressed store, hash-verified

280
281// some extra tests
282func TestBitmapExtraCOW(t *testing.T) {
283 for N := uint32(1); N <= 65536; N *= 2 {
284 t.Run("extra tests"+strconv.Itoa(int(N)), func(t *testing.T) {
285 for gap := uint32(1); gap <= 65536; gap *= 2 {
286 bs1 := bitset.New(0)
287 rb1 := NewBitmap()
288 rb1.SetCopyOnWrite(true)
289
290 for x := uint32(0); x <= N; x += gap {
291 bs1.Set(uint(x))
292 rb1.Add(x)
293 }
294
295 assert.EqualValues(t, rb1.GetCardinality(), bs1.Count())
296 assert.True(t, equalsBitSet(bs1, rb1))
297
298 for offset := uint32(1); offset <= gap; offset *= 2 {
299 bs2 := bitset.New(0)
300 rb2 := NewBitmap()
301 rb2.SetCopyOnWrite(true)
302
303 for x := uint32(0); x <= N; x += gap {
304 bs2.Set(uint(x + offset))
305 rb2.Add(x + offset)
306 }
307
308 assert.EqualValues(t, rb2.GetCardinality(), bs2.Count())
309 assert.True(t, equalsBitSet(bs2, rb2))
310
311 clonebs1 := bs1.Clone()
312 clonebs1.InPlaceIntersection(bs2)
313 if !equalsBitSet(clonebs1, And(rb1, rb2)) {
314 v := rb1.Clone()
315 v.And(rb2)
316
317 assert.True(t, equalsBitSet(clonebs1, v))
318 }
319
320 // testing OR
321 clonebs1 = bs1.Clone()
322 clonebs1.InPlaceUnion(bs2)
323
324 assert.True(t, equalsBitSet(clonebs1, Or(rb1, rb2)))
325
326 // testing XOR
327 clonebs1 = bs1.Clone()
328 clonebs1.InPlaceSymmetricDifference(bs2)
329
330 assert.True(t, equalsBitSet(clonebs1, Xor(rb1, rb2)))
331
332 //testing NOTAND
333 clonebs1 = bs1.Clone()
334 clonebs1.InPlaceDifference(bs2)
335
336 assert.True(t, equalsBitSet(clonebs1, AndNot(rb1, rb2)))
337 }
338 }
339 })

Callers

nothing calls this directly

Calls 11

SetCopyOnWriteMethod · 0.95
AddMethod · 0.95
GetCardinalityMethod · 0.95
CloneMethod · 0.95
NewBitmapFunction · 0.70
equalsBitSetFunction · 0.70
AndFunction · 0.70
OrFunction · 0.70
XorFunction · 0.70
AndNotFunction · 0.70
AndMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…