Skip to content

Commit

Permalink
maxBE128 implementation failing with similar values (#433)
Browse files Browse the repository at this point in the history
* Create failing test to exercise maxBE128 bug

* fix: JAE => JBE

Co-authored-by: Achille Roussel <[email protected]>
  • Loading branch information
Larry Marburger and Achille Roussel authored Dec 6, 2022
1 parent b37e188 commit 813b06a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions page_bounds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math/rand"
"reflect"
"testing"

"github.com/segmentio/parquet-go/internal/quick"
Expand Down Expand Up @@ -168,6 +169,55 @@ func TestBoundsFloat64(t *testing.T) {
}
}

func TestBE128MinMaxSimilar(t *testing.T) {
var min [16]byte

// Test values:
// [1 1 ... 1 1]
// [0 1 ... 1 1]
// ...
// [0 0 ... 0 1]
// [0 0 ... 0 0]
for i := 0; i < 17; i++ {
var max [16]byte
for j := i; j < 16; j++ {
max[j] = 1
}
testBE182MinMaxPerm(t, min, max)
}

// Test values:
// [0 0 ... 0 0]
// [1 0 ... 0 0]
// ...
// [1 1 ... 1 0]
// [1 1 ... 1 1]
for i := 0; i < 17; i++ {
var max [16]byte
for j := 0; j < i; j++ {
max[j] = 1
}
testBE182MinMaxPerm(t, min, max)
}
}

func testBE182MinMaxPerm(t *testing.T, min, max [16]byte) {
testBE128MinMax(t, min[:], max[:], [][16]byte{min, max})
testBE128MinMax(t, min[:], max[:], [][16]byte{max, min})
}

func testBE128MinMax(t *testing.T, min, max []byte, data [][16]byte) {
bmin := minBE128(data)
if !reflect.DeepEqual(bmin, min[:]) {
t.Errorf("unexpected min value\nexpected %v\n got %v", min, bmin)
}

bmax := maxBE128(data)
if !reflect.DeepEqual(bmax, max[:]) {
t.Errorf("unexpected max value\nexpected %v\n got %v", max, bmax)
}
}

func TestBoundsBE128(t *testing.T) {
err := quick.Check(func(values [][16]byte) bool {
min := [16]byte{}
Expand Down
2 changes: 1 addition & 1 deletion page_max_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ loop:
BSWAPQ R8
BSWAPQ R9
CMPQ R8, R9
JAE next
JBE next
more:
MOVQ AX, BX
next:
Expand Down

0 comments on commit 813b06a

Please sign in to comment.