github.com/parquet-go/parquet-go@v0.20.0/compare_test.go (about)

     1  package parquet
     2  
     3  import "testing"
     4  
     5  func assertCompare(t *testing.T, a, b Value, cmp func(Value, Value) int, want int) {
     6  	if got := cmp(a, b); got != want {
     7  		t.Errorf("compare(%v, %v): got=%d want=%d", a, b, got, want)
     8  	}
     9  }
    10  
    11  func TestCompareNullsFirst(t *testing.T) {
    12  	cmp := CompareNullsFirst(Int32Type.Compare)
    13  	assertCompare(t, Value{}, Value{}, cmp, 0)
    14  	assertCompare(t, Value{}, ValueOf(int32(0)), cmp, -1)
    15  	assertCompare(t, ValueOf(int32(0)), Value{}, cmp, +1)
    16  	assertCompare(t, ValueOf(int32(0)), ValueOf(int32(1)), cmp, -1)
    17  }
    18  
    19  func TestCompareNullsLast(t *testing.T) {
    20  	cmp := CompareNullsLast(Int32Type.Compare)
    21  	assertCompare(t, Value{}, Value{}, cmp, 0)
    22  	assertCompare(t, Value{}, ValueOf(int32(0)), cmp, +1)
    23  	assertCompare(t, ValueOf(int32(0)), Value{}, cmp, -1)
    24  	assertCompare(t, ValueOf(int32(0)), ValueOf(int32(1)), cmp, -1)
    25  }
    26  
    27  func BenchmarkCompareBE128(b *testing.B) {
    28  	v1 := [16]byte{}
    29  	v2 := [16]byte{}
    30  
    31  	for i := 0; i < b.N; i++ {
    32  		compareBE128(&v1, &v2)
    33  	}
    34  }
    35  
    36  func BenchmarkLessBE128(b *testing.B) {
    37  	v1 := [16]byte{}
    38  	v2 := [16]byte{}
    39  
    40  	for i := 0; i < b.N; i++ {
    41  		lessBE128(&v1, &v2)
    42  	}
    43  }