github.com/parquet-go/parquet-go@v0.21.1-0.20240501160520-b3c3a0c3ed6f/encoding/rle/rle_test.go (about)

     1  package rle
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/parquet-go/parquet-go/encoding/fuzz"
     7  	"github.com/parquet-go/parquet-go/internal/quick"
     8  )
     9  
    10  func FuzzEncodeBoolean(f *testing.F) {
    11  	fuzz.EncodeBoolean(f, &Encoding{BitWidth: 1})
    12  }
    13  
    14  func FuzzEncodeLevels(f *testing.F) {
    15  	fuzz.EncodeLevels(f, &Encoding{BitWidth: 8})
    16  }
    17  
    18  func FuzzEncodeInt32(f *testing.F) {
    19  	fuzz.EncodeInt32(f, &Encoding{BitWidth: 32})
    20  }
    21  
    22  func TestEncodeInt32IndexEqual8Contiguous(t *testing.T) {
    23  	testEncodeInt32IndexEqual8Contiguous(t, encodeInt32IndexEqual8Contiguous)
    24  }
    25  
    26  func testEncodeInt32IndexEqual8Contiguous(t *testing.T, f func([][8]int32) int) {
    27  	t.Helper()
    28  
    29  	err := quick.Check(func(words [][8]int32) bool {
    30  		want := 0
    31  
    32  		for want < len(words) && words[want] != broadcast8x4(words[want][0]) {
    33  			want++
    34  		}
    35  
    36  		if got := f(words); got != want {
    37  			t.Errorf("want=%d got=%d", want, got)
    38  			return false
    39  		}
    40  
    41  		return true
    42  	})
    43  	if err != nil {
    44  		t.Error(err)
    45  	}
    46  }
    47  
    48  func BenchmarkEncodeInt32IndexEqual8Contiguous(b *testing.B) {
    49  	benchmarkEncodeInt32IndexEqual8Contiguous(b, encodeInt32IndexEqual8Contiguous)
    50  }
    51  
    52  func benchmarkEncodeInt32IndexEqual8Contiguous(b *testing.B, f func([][8]int32) int) {
    53  	words := make([][8]int32, 1000)
    54  	for i := range words {
    55  		words[i][0] = 1
    56  	}
    57  	for i := 0; i < b.N; i++ {
    58  		_ = f(words)
    59  	}
    60  	b.SetBytes(32 * int64(len(words)))
    61  }