mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
The module already called itself github.com/luxfi/node while containing no node in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and the Go column of the matrix measured a VM plugin. A repo that fetches the thing it claims to be has not replaced it, so the Go sources move in — 1515 files, the daemon and everything under it — and the build reaches outside this module for nothing. Rust and C++ sit beside it unchanged and are still measured against it by the differential. That is the point of one repo: the reference implementation and the two ports are the same checkout, so parity is a thing you can run rather than a thing you assert. Verified: builds, and the closure carries no lux-private — checked at build time rather than believed. The daemon starts twelve chains on a local network (P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
114 lines
2.1 KiB
Go
114 lines
2.1 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package utils
|
|
|
|
import (
|
|
"cmp"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var _ Sortable[sortable] = sortable(0)
|
|
|
|
type sortable int
|
|
|
|
func (s sortable) Compare(other sortable) int {
|
|
return cmp.Compare(s, other)
|
|
}
|
|
|
|
func TestSortSliceSortable(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
var s []sortable
|
|
Sort(s)
|
|
require.True(IsSortedAndUnique(s))
|
|
require.Empty(s)
|
|
|
|
s = []sortable{1}
|
|
Sort(s)
|
|
require.True(IsSortedAndUnique(s))
|
|
require.Equal([]sortable{1}, s)
|
|
|
|
s = []sortable{1, 1}
|
|
Sort(s)
|
|
require.Equal([]sortable{1, 1}, s)
|
|
|
|
s = []sortable{1, 2}
|
|
Sort(s)
|
|
require.True(IsSortedAndUnique(s))
|
|
require.Equal([]sortable{1, 2}, s)
|
|
|
|
s = []sortable{2, 1}
|
|
Sort(s)
|
|
require.True(IsSortedAndUnique(s))
|
|
require.Equal([]sortable{1, 2}, s)
|
|
|
|
s = []sortable{1, 2, 1}
|
|
Sort(s)
|
|
require.Equal([]sortable{1, 1, 2}, s)
|
|
|
|
s = []sortable{2, 1, 2}
|
|
Sort(s)
|
|
require.Equal([]sortable{1, 2, 2}, s)
|
|
|
|
s = []sortable{3, 1, 2}
|
|
Sort(s)
|
|
require.Equal([]sortable{1, 2, 3}, s)
|
|
}
|
|
|
|
func TestIsSortedAndUniqueSortable(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
var s []sortable
|
|
require.True(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{}
|
|
require.True(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{1}
|
|
require.True(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{1, 2}
|
|
require.True(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{1, 1}
|
|
require.False(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{2, 1}
|
|
require.False(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{1, 2, 1}
|
|
require.False(IsSortedAndUnique(s))
|
|
|
|
s = []sortable{1, 2, 0}
|
|
require.False(IsSortedAndUnique(s))
|
|
}
|
|
|
|
func TestSortByHash(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
s := [][]byte{}
|
|
SortByHash(s)
|
|
require.Empty(s)
|
|
|
|
s = [][]byte{{1}}
|
|
SortByHash(s)
|
|
require.Len(s, 1)
|
|
require.Equal([]byte{1}, s[0])
|
|
|
|
s = [][]byte{{1}, {2}}
|
|
SortByHash(s)
|
|
require.Len(s, 2)
|
|
require.Equal([]byte{1}, s[0])
|
|
require.Equal([]byte{2}, s[1])
|
|
|
|
for i := byte(0); i < 100; i++ {
|
|
s = [][]byte{{i}, {i + 1}, {i + 2}}
|
|
SortByHash(s)
|
|
require.Len(s, 3)
|
|
require.True(IsSortedAndUniqueByHash(s))
|
|
}
|
|
}
|