From 65b19168b39c07444c5958cb3546778cd9aeae49 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Tue, 13 Jun 2017 13:42:23 -0500 Subject: [PATCH] add test for bitcount test on remove --- roaring/roaring_test.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/roaring/roaring_test.go b/roaring/roaring_test.go index d1bb609e2..07fd99d84 100644 --- a/roaring/roaring_test.go +++ b/roaring/roaring_test.go @@ -325,10 +325,18 @@ func testBitmapQuick(t *testing.T, n int, min, max uint64) { m := make(map[uint64]struct{}) // Add values to the bitmap and set. + manual_count := uint64(0) for _, v := range a { - bm.Add(v) + new_bit, _ := bm.Add(v) + if new_bit { + manual_count++ + } m[v] = struct{}{} } + //check count + if manual_count != bm.Count() { + t.Fatalf("expected bitmap Add count to be: %d got: %d", manual_count, bm.Count()) + } // Verify existence. for _, v := range a { @@ -352,8 +360,16 @@ func testBitmapQuick(t *testing.T, n int, min, max uint64) { } // Remove all values in random order. + fmt.Println(len(a)) for _, i := range rand.Perm(len(a)) { - bm.Remove(a[i]) + removed, _ := bm.Remove(a[i]) + if removed { + manual_count-- + } + //check count + if manual_count != bm.Count() { + t.Fatalf("expected bitmap Remove count to be: %d got: %d", manual_count, bm.Count()) + } } // Verify all values have been removed.