From 80b4cf24d4963910cd72df2c49b7647c560d18dd Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 17 Sep 2024 15:28:57 +1000 Subject: [PATCH] Test FromUnsafeBytes return count --- roaring64/serialization_test.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/roaring64/serialization_test.go b/roaring64/serialization_test.go index 31d0e514..5660133f 100644 --- a/roaring64/serialization_test.go +++ b/roaring64/serialization_test.go @@ -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() @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) } @@ -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)) }