From 10490a3402b50df35c61b358c5325f4f63bf2966 Mon Sep 17 00:00:00 2001 From: Travis Date: Thu, 22 Jun 2017 11:03:05 -0500 Subject: [PATCH] Improves test coverage for `IntersectionCount` operations --- roaring/roaring_test.go | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/roaring/roaring_test.go b/roaring/roaring_test.go index bc706cf84..8b784ff0f 100644 --- a/roaring/roaring_test.go +++ b/roaring/roaring_test.go @@ -403,7 +403,7 @@ func TestBitmap_Flip_After(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) + bm0 := roaring.NewBitmap(0, 1, 1000001, 1000002, 1000003) bm1 := roaring.NewBitmap(0, 50000, 1000001, 1000002) if n := bm0.IntersectionCount(bm1); n != 3 { @@ -413,6 +413,49 @@ func TestBitmap_IntersectionCount_ArrayArray(t *testing.T) { } } +// Ensure bitmap can return the number of intersecting bits in two bitmaps. +func TestBitmap_IntersectionCount_ArrayRun(t *testing.T) { + bm0 := roaring.NewBitmap(0, 1000001, 1000002, 1000003) + bm1 := roaring.NewBitmap(0, 1, 2, 3, 4, 5, 1000000, 1000002, 1000003, 1000004, 1000005, 1000006) + bm1.Optimize() // convert to runs + + if n := bm0.IntersectionCount(bm1); n != 3 { + t.Fatalf("unexpected n: %d", n) + } else if n := bm1.IntersectionCount(bm0); n != 3 { + t.Fatalf("unexpected n (reverse): %d", n) + } +} + +// Ensure bitmap can return the number of intersecting bits in two bitmaps. +func TestBitmap_IntersectionCount_RunRun(t *testing.T) { + bm0 := roaring.NewBitmap(3, 4, 5, 6, 7, 8, 1000001, 1000002, 1000003, 1000004) + bm0.Optimize() // convert to runs + bm1 := roaring.NewBitmap(0, 1, 2, 3, 4, 5, 1000000, 1000002, 1000003, 1000004, 1000005, 1000006) + bm1.Optimize() // convert to runs + + if n := bm0.IntersectionCount(bm1); n != 6 { + t.Fatalf("unexpected n: %d", n) + } else if n := bm1.IntersectionCount(bm0); n != 6 { + t.Fatalf("unexpected n (reverse): %d", n) + } +} + +// Ensure bitmap can return the number of intersecting bits in two bitmaps. +func TestBitmap_IntersectionCount_BitmapRun(t *testing.T) { + bm0 := roaring.NewBitmap() + for i := uint64(3); i <= 1000006; i += 2 { + bm0.Add(i) + } + bm1 := roaring.NewBitmap(0, 1, 2, 3, 4, 5, 1000000, 1000002, 1000003, 1000004, 1000005, 1000006) + bm1.Optimize() // convert to runs + + if n := bm0.IntersectionCount(bm1); n != 4 { + t.Fatalf("unexpected n: %d", n) + } else if n := bm1.IntersectionCount(bm0); n != 4 { + t.Fatalf("unexpected n (reverse): %d", n) + } +} + // Ensure bitmap can return the number of intersecting bits in two bitmaps. func TestBitmap_IntersectionCount_ArrayBitmap(t *testing.T) { bm0 := roaring.NewBitmap(1, 70, 200, 4097, 4098)