mirror of
https://github.com/luxfi/database.git
synced 2026-10-30 15:01:18 +00:00
- Update helpers_test.go to use github.com/luxfi/math - Remove github.com/luxfi/utils dependency - Upgrade to math v1.2.0
52 lines
1.0 KiB
Go
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))
|
|
}
|