github.com/parquet-go/parquet-go@v0.20.0/internal/bytealg/count_test.go (about)

     1  package bytealg_test
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/parquet-go/parquet-go/internal/bytealg"
     8  	"github.com/parquet-go/parquet-go/internal/quick"
     9  )
    10  
    11  func TestCount(t *testing.T) {
    12  	err := quick.Check(func(data []byte) bool {
    13  		data = bytes.Repeat(data, 8)
    14  		for _, c := range data {
    15  			n1 := bytes.Count(data, []byte{c})
    16  			n2 := bytealg.Count(data, c)
    17  			if n1 != n2 {
    18  				t.Errorf("got=%d want=%d", n2, n1)
    19  				return false
    20  			}
    21  		}
    22  		return true
    23  	})
    24  	if err != nil {
    25  		t.Error(err)
    26  	}
    27  }
    28  
    29  func BenchmarkCount(b *testing.B) {
    30  	forEachBenchmarkBufferSize(b, func(b *testing.B, bufferSize int) {
    31  		data := make([]byte, bufferSize)
    32  		for i := range data {
    33  			data[i] = byte(i)
    34  		}
    35  		for i := 0; i < b.N; i++ {
    36  			bytealg.Count(data, 0)
    37  		}
    38  	})
    39  }