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