Files
database/helpers_test.go
zeekay 8ff7f051d5 refactor: replace utils.IsSortedBytes with luxmath.IsSortedBytes
- Update helpers_test.go to use github.com/luxfi/math
- Remove github.com/luxfi/utils dependency
- Upgrade to math v1.2.0
2025-12-24 15:41:22 -08:00

52 lines
1.0 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package database
import (
"math/rand"
"slices"
"testing"
"time"
"github.com/stretchr/testify/require"
luxmath "github.com/luxfi/math"
)
func TestSortednessUint64(t *testing.T) {
seed := time.Now().UnixNano()
t.Log("Seed: ", seed)
rand := rand.New(rand.NewSource(seed)) //#nosec G404
ints := make([]uint64, 1024)
for i := range ints {
ints[i] = rand.Uint64()
}
slices.Sort(ints)
intBytes := make([][]byte, 1024)
for i, val := range ints {
intBytes[i] = PackUInt64(val)
}
require.True(t, luxmath.IsSortedBytes(intBytes))
}
func TestSortednessUint32(t *testing.T) {
seed := time.Now().UnixNano()
t.Log("Seed: ", seed)
rand := rand.New(rand.NewSource(seed)) //#nosec G404
ints := make([]uint32, 1024)
for i := range ints {
ints[i] = rand.Uint32()
}
slices.Sort(ints)
intBytes := make([][]byte, 1024)
for i, val := range ints {
intBytes[i] = PackUInt32(val)
}
require.True(t, luxmath.IsSortedBytes(intBytes))
}