Skip to content

Commit

Permalink
added empty and equivlence testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tgruben committed May 30, 2017
1 parent 7090ee4 commit b5bd843
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
1 change: 0 additions & 1 deletion roaring/roaring.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,7 +1648,6 @@ func xorArrayBitmap(a, b *container) *container {
if b.bitmapContains(v) {
output.remove(v)
} else {

output.add(v)
}
}
Expand Down
27 changes: 25 additions & 2 deletions roaring/roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down

0 comments on commit b5bd843

Please sign in to comment.