Files
zeekay 7cf87b230b node-unified is the node
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.
2026-09-07 16:15:25 -07:00

169 lines
3.0 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package linked
import (
"testing"
"github.com/stretchr/testify/require"
)
func flattenForwards[T any](l *List[T]) []T {
var s []T
for e := l.Front(); e != nil; e = e.Next() {
s = append(s, e.Value)
}
return s
}
func flattenBackwards[T any](l *List[T]) []T {
var s []T
for e := l.Back(); e != nil; e = e.Prev() {
s = append(s, e.Value)
}
return s
}
func TestList_Empty(t *testing.T) {
require := require.New(t)
l := NewList[int]()
require.Empty(flattenForwards(l))
require.Empty(flattenBackwards(l))
require.Zero(l.Len())
}
func TestList_PushBack(t *testing.T) {
require := require.New(t)
l := NewList[int]()
for i := 0; i < 5; i++ {
l.PushBack(&ListElement[int]{
Value: i,
})
}
require.Equal([]int{0, 1, 2, 3, 4}, flattenForwards(l))
require.Equal([]int{4, 3, 2, 1, 0}, flattenBackwards(l))
require.Equal(5, l.Len())
}
func TestList_PushBack_Duplicate(t *testing.T) {
require := require.New(t)
l := NewList[int]()
e := &ListElement[int]{
Value: 0,
}
l.PushBack(e)
l.PushBack(e)
require.Equal([]int{0}, flattenForwards(l))
require.Equal([]int{0}, flattenBackwards(l))
require.Equal(1, l.Len())
}
func TestList_PushFront(t *testing.T) {
require := require.New(t)
l := NewList[int]()
for i := 0; i < 5; i++ {
l.PushFront(&ListElement[int]{
Value: i,
})
}
require.Equal([]int{4, 3, 2, 1, 0}, flattenForwards(l))
require.Equal([]int{0, 1, 2, 3, 4}, flattenBackwards(l))
require.Equal(5, l.Len())
}
func TestList_PushFront_Duplicate(t *testing.T) {
require := require.New(t)
l := NewList[int]()
e := &ListElement[int]{
Value: 0,
}
l.PushFront(e)
l.PushFront(e)
require.Equal([]int{0}, flattenForwards(l))
require.Equal([]int{0}, flattenBackwards(l))
require.Equal(1, l.Len())
}
func TestList_Remove(t *testing.T) {
require := require.New(t)
l := NewList[int]()
e0 := &ListElement[int]{
Value: 0,
}
e1 := &ListElement[int]{
Value: 1,
}
e2 := &ListElement[int]{
Value: 2,
}
l.PushBack(e0)
l.PushBack(e1)
l.PushBack(e2)
l.Remove(e1)
require.Equal([]int{0, 2}, flattenForwards(l))
require.Equal([]int{2, 0}, flattenBackwards(l))
require.Equal(2, l.Len())
require.Nil(e1.next)
require.Nil(e1.prev)
require.Nil(e1.list)
}
func TestList_MoveToFront(t *testing.T) {
require := require.New(t)
l := NewList[int]()
e0 := &ListElement[int]{
Value: 0,
}
e1 := &ListElement[int]{
Value: 1,
}
l.PushFront(e0)
l.PushFront(e1)
l.MoveToFront(e0)
require.Equal([]int{0, 1}, flattenForwards(l))
require.Equal([]int{1, 0}, flattenBackwards(l))
require.Equal(2, l.Len())
}
func TestList_MoveToBack(t *testing.T) {
require := require.New(t)
l := NewList[int]()
e0 := &ListElement[int]{
Value: 0,
}
e1 := &ListElement[int]{
Value: 1,
}
l.PushFront(e0)
l.PushFront(e1)
l.MoveToBack(e1)
require.Equal([]int{0, 1}, flattenForwards(l))
require.Equal([]int{1, 0}, flattenBackwards(l))
require.Equal(2, l.Len())
}