Skip to content

Commit

Permalink
Test FromUnsafeBytes return count
Browse files Browse the repository at this point in the history
  • Loading branch information
anacrolix committed Sep 17, 2024
1 parent 6fa0aef commit 80b4cf2
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions roaring64/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ import (
"github.com/stretchr/testify/require"
)

func fromUnsafeBytesChecked(t *testing.T, unsafeBm *Bitmap, b []byte) {
var r bytes.Reader
r.Reset(b)
var safeBm Bitmap
safeCount, err := safeBm.ReadFrom(&r)
unsafeCount, err := unsafeBm.FromUnsafeBytes(b)
require.NoError(t, err)
require.NoError(t, err)
assert.EqualValues(t, safeCount, unsafeCount)
assert.True(t, safeBm.Equals(unsafeBm))
}

func TestSerializationOfEmptyBitmap(t *testing.T) {
rb := NewBitmap()

Expand All @@ -34,8 +46,7 @@ func TestSerializationOfEmptyBitmap(t *testing.T) {
assert.True(t, rb.Equals(newrb))

newrb2 := NewBitmap()
_, err = newrb2.FromUnsafeBytes(data)
require.NoError(t, err)
fromUnsafeBytesChecked(t, newrb2, data)
assert.True(t, rb.Equals(newrb2))
}

Expand Down Expand Up @@ -70,8 +81,7 @@ func TestSerializationBasic037(t *testing.T) {
assert.True(t, rb.Equals(newrb))

newrb2 := NewBitmap()
_, err = newrb2.FromUnsafeBytes(data)
require.NoError(t, err)
fromUnsafeBytesChecked(t, newrb2, data)
assert.True(t, rb.Equals(newrb2))
}

Expand Down Expand Up @@ -113,8 +123,7 @@ func TestSerializationToFile038(t *testing.T) {
assert.True(t, rb.Equals(newrb))

newrb2 := NewBitmap()
_, err = newrb2.FromUnsafeBytes(buf.Bytes())
require.NoError(t, err)
fromUnsafeBytesChecked(t, newrb2, buf.Bytes())
assert.True(t, rb.Equals(newrb2))
}

Expand All @@ -136,8 +145,7 @@ func TestSerializationBasic2_041(t *testing.T) {
assert.True(t, rb.Equals(newrb))

newrb2 := NewBitmap()
_, err = newrb2.FromUnsafeBytes(data)
require.NoError(t, err)
fromUnsafeBytesChecked(t, newrb2, data)
assert.True(t, rb.Equals(newrb2))
}

Expand All @@ -162,8 +170,7 @@ func TestSerializationBasic3_042(t *testing.T) {
assert.True(t, newrb.Equals(rb))

newrb2 := NewBitmap()
_, err = newrb2.FromUnsafeBytes(data)
require.NoError(t, err)
fromUnsafeBytesChecked(t, newrb2, data)
assert.True(t, rb.Equals(newrb2))
}

Expand Down

0 comments on commit 80b4cf2

Please sign in to comment.