Skip to content

Commit

Permalink
Update fuzz function
Browse files Browse the repository at this point in the history
  • Loading branch information
b97tsk committed Jan 20, 2024
1 parent 994852a commit 59e9d2a
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package intervals_test

import (
"crypto/rand"
"encoding/binary"
"slices"
"testing"

Expand Down Expand Up @@ -107,31 +106,28 @@ func FuzzSymmetricDifference(f *testing.F) {
}

func fuzz(f *testing.F, ff func(t *testing.T, x, y Set[elems.Uint8])) {
data := make([]byte, 8*4)
data := make([]byte, 32)
args := make([]any, len(data))

for i := 0; i < 10; i++ {
if _, err := rand.Read(data); err != nil {
f.Fatal(err)
}

f.Add(
binary.LittleEndian.Uint64(data),
binary.LittleEndian.Uint64(data[8:]),
binary.LittleEndian.Uint64(data[16:]),
binary.LittleEndian.Uint64(data[24:]),
)
}

f.Fuzz(func(t *testing.T, x1, x2, y1, y2 uint64) {
xs, ys := make([]byte, 8*2), make([]byte, 8*2)

for i, u64 := range []uint64{x1, x2} {
binary.LittleEndian.PutUint64(xs[i*8:], u64)
for i, v := range data {
args[i] = v
}

for i, u64 := range []uint64{y1, y2} {
binary.LittleEndian.PutUint64(ys[i*8:], u64)
}
f.Add(args...)
}

f.Fuzz(func(
t *testing.T,
x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15,
y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15 byte,
) {
xs := []byte{x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15}
ys := []byte{y0, y1, y2, y3, y4, y5, y6, y7, y8, y9, y10, y11, y12, y13, y14, y15}

slices.Sort(xs)
slices.Sort(ys)
Expand Down

0 comments on commit 59e9d2a

Please sign in to comment.