github.com/parquet-go/parquet-go@v0.20.0/buffer_internal_test.go (about) 1 package parquet 2 3 import ( 4 "fmt" 5 "math/rand" 6 "testing" 7 ) 8 9 func TestBufferAlwaysCorrectSize(t *testing.T) { 10 var p bufferPool 11 for i := 0; i < 1000; i++ { 12 n := rand.Intn(1024 * 1024) 13 b := p.get(n) 14 if len(b.data) != n { 15 t.Fatalf("Expected buffer of size %d, got %d", n, len(b.data)) 16 } 17 b.unref() 18 } 19 } 20 21 func TestBufferPoolBucketIndexAndSizeOf(t *testing.T) { 22 tests := []struct { 23 size int 24 bucketIndex int 25 bucketSize int 26 }{ 27 {size: 0, bucketIndex: 0, bucketSize: 4096}, 28 {size: 1, bucketIndex: 0, bucketSize: 4096}, 29 {size: 2049, bucketIndex: 0, bucketSize: 4096}, 30 {size: 4096, bucketIndex: 0, bucketSize: 4096}, 31 {size: 4097, bucketIndex: 1, bucketSize: 8192}, 32 {size: 8192, bucketIndex: 1, bucketSize: 8192}, 33 {size: 8193, bucketIndex: 2, bucketSize: 16384}, 34 {size: 16384, bucketIndex: 2, bucketSize: 16384}, 35 {size: 16385, bucketIndex: 3, bucketSize: 32768}, 36 {size: 32768, bucketIndex: 3, bucketSize: 32768}, 37 {size: 32769, bucketIndex: 4, bucketSize: 65536}, 38 {size: 262143, bucketIndex: 6, bucketSize: 262144}, 39 {size: 262144, bucketIndex: 6, bucketSize: 262144}, 40 {size: 262145, bucketIndex: 7, bucketSize: 393216}, 41 } 42 43 for _, test := range tests { 44 t.Run(fmt.Sprintf("size=%d", test.size), func(t *testing.T) { 45 bucketIndex, bucketSize := bufferPoolBucketIndexAndSizeOfGet(test.size) 46 47 if bucketIndex != test.bucketIndex { 48 t.Errorf("wrong bucket index, want %d but got %d", test.bucketIndex, bucketIndex) 49 } 50 51 if bucketSize != test.bucketSize { 52 t.Errorf("wrong bucket size, want %d but got %d", test.bucketSize, bucketSize) 53 } 54 }) 55 } 56 }