From b5bd8433ccc43854159d78048e63a3abd113d9a9 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Tue, 30 May 2017 13:27:11 -0500 Subject: [PATCH] added empty and equivlence testing --- roaring/roaring.go | 1 - roaring/roaring_test.go | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 8d477ba10..4a54d3975 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -1648,7 +1648,6 @@ func xorArrayBitmap(a, b *container) *container { if b.bitmapContains(v) { output.remove(v) } else { - output.add(v) } } diff --git a/roaring/roaring_test.go b/roaring/roaring_test.go index 32492d870..11bab1c78 100644 --- a/roaring/roaring_test.go +++ b/roaring/roaring_test.go @@ -137,8 +137,25 @@ func TestBitmap_Xor_ArrayArray(t *testing.T) { if n := result.Count(); n != 2 { t.Fatalf("unexpected n: %d", n) } + + //equivalence array test + result = result.Xor(result) + if n := result.Count(); n > 0 { + t.Fatalf("unexpected n: %d", n) + } + } +//empty array test +func TestBitmap_Xor_Empty(t *testing.T) { + bm1 := roaring.NewBitmap(0, 50000, 1000001, 1000002) + empty := roaring.NewBitmap() + result := bm1.Xor(empty) + + if n := result.Count(); n != 4 { + t.Fatalf("unexpected n: %d", n) + } +} func TestBitmap_Xor_ArrayBitmap(t *testing.T) { bm0 := roaring.NewBitmap(1, 70, 200, 4097, 4098) bm1 := roaring.NewBitmap() @@ -150,14 +167,22 @@ func TestBitmap_Xor_ArrayBitmap(t *testing.T) { if n := result.Count(); n != 4999 { t.Fatalf("unexpected n: %d", n) } + + //equivalence bitmap test + result = result.Xor(result) + if n := result.Count(); n > 0 { + t.Fatalf("unexpected n: %d", n) + } } func TestBitmap_Xor_BitmapBitmap(t *testing.T) { bm0 := roaring.NewBitmap() bm1 := roaring.NewBitmap() + for i := uint64(0); i < 10000; i += 2 { bm1.Add(i) } + for i := uint64(1); i < 10000; i += 2 { bm0.Add(i) } @@ -168,8 +193,6 @@ func TestBitmap_Xor_BitmapBitmap(t *testing.T) { } } - - // Ensure bitmap can return the number of intersecting bits in two bitmaps. func TestBitmap_IntersectionCount_ArrayArray(t *testing.T) { bm0 := roaring.NewBitmap(0, 1000001, 1000002, 1000003)