Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix existing test failures #3

Merged
merged 2 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions roaring/roaring_pooling_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package roaring

import (
"testing"

"github.com/google/go-cmp/cmp"
)

// TestBitmap_Reset verifies that the Reset method always restores a Bitmap
// to a state indistinguishable from a new one.
func TestBitmap_Reset(t *testing.T) {
bm := NewBitmapWithDefaultPooling(10)

i := uint64(0)
for {
if i >= 10000 {
break
}

bm.Add(10000 * i)
i++
}
untouched := NewBitmapWithDefaultPooling(10)
bm.Reset()

if !cmp.Equal(untouched, bm, cmp.Comparer(func(x, y Bitmap) bool {
if x.Containers.Size() != y.Containers.Size() {
return false
}
if x.Containers.Count() != y.Containers.Count() {
return false
}
if x.opN != y.opN {
return false
}
if x.OpWriter != y.OpWriter {
return false
}
return true
})) {
t.Fatalf("Reset bitmap: %+v is not identical to new bitmap: %+v", bm, untouched)
}
}
22 changes: 0 additions & 22 deletions roaring/roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1406,28 +1406,6 @@ func TestBitmap_Intersect(t *testing.T) {
}
}

// TestBitmap_Reset verifies that the Reset method always restores a Bitmap
// to a state indistinguishable from a new one.
func TestBitmap_Reset(t *testing.T) {
bm := roaring.NewBitmapWithDefaultPooling(10)

i := uint64(0)
for {
if i >= 10000 {
break
}

bm.Add(10000 * i)
i++
}

untouched := roaring.NewBitmapWithDefaultPooling(10)
bm.Reset()
if !reflect.DeepEqual(untouched, bm) {
t.Fatalf("Reset bitmap: %+v is not identical to new bitmap: %+v", bm, untouched)
}
}

func BenchmarkGetBenchData(b *testing.B) {
for i := 0; i < b.N; i++ {
sampleData = benchmarkSampleData{}
Expand Down
2 changes: 2 additions & 0 deletions translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,8 @@ func (s *TranslateFile) size() int64 {

// isReadOnly returns true if this store is being replicated from a primary store.
func (s *TranslateFile) isReadOnly() bool {
s.mu.RLock()
defer s.mu.RUnlock()
return s.PrimaryTranslateStore != nil
}

Expand Down