github.com/fraugster/parquet-go@v0.12.0/deltabp_test.go (about)

     1  package goparquet
     2  
     3  import (
     4  	"bytes"
     5  	"math/rand"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func buildDataDelta(l int) []int32 {
    13  	res := make([]int32, l)
    14  	for i := 0; i < l; i++ {
    15  		res[i] = rand.Int31()
    16  	}
    17  
    18  	return res
    19  }
    20  
    21  func TestDelta(t *testing.T) {
    22  	for i := 1; i < 32; i++ {
    23  		data := &bytes.Buffer{}
    24  		enc := &deltaBitPackEncoder32{
    25  			blockSize:      128,
    26  			miniBlockCount: 4,
    27  		}
    28  		assert.NoError(t, enc.init(data))
    29  		to1 := buildDataDelta(8*1024 + 5)
    30  		for _, i := range to1 {
    31  			require.NoError(t, enc.addInt32(i))
    32  		}
    33  		assert.NoError(t, enc.Close())
    34  
    35  		buf2 := bytes.NewReader(data.Bytes())
    36  		dec := &deltaBitPackDecoder32{
    37  			blockSize:      128,
    38  			miniBlockCount: 4,
    39  		}
    40  		assert.NoError(t, dec.init(buf2))
    41  		var toR []int32
    42  		total := len(to1)
    43  		for j := 0; j < total; j++ {
    44  			d, err := dec.next()
    45  			if err != nil {
    46  				break
    47  			}
    48  			toR = append(toR, d)
    49  		}
    50  		assert.Equal(t, toR, to1)
    51  	}
    52  }