forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to ensure that database packing produces sorted values (ava-…
- Loading branch information
1 parent
e17a6ca
commit d6004f2
Showing
3 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package database | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"golang.org/x/exp/slices" | ||
|
||
"github.com/ava-labs/avalanchego/utils" | ||
) | ||
|
||
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, utils.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, utils.IsSortedBytes(intBytes)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters