lseq/golang/lseq_test.go

44 lines
944 B
Go
Raw Permalink Normal View History

2025-12-12 23:18:05 -08:00
package lseq
import (
"testing"
)
func TestStringEncoding(t *testing.T) {
// Basic sanity checks for encoding/decoding
cases := []struct {
numbers []uint64
want string
}{
{[]uint64{0}, "-"},
{[]uint64{63}, "z"},
{[]uint64{0, 1}, "--0"},
{[]uint64{0, 4095}, "-zz"},
}
for _, tc := range cases {
got := numbersToID(tc.numbers)
if got != tc.want {
t.Errorf("numbersToID(%v) = %q, want %q", tc.numbers, got, tc.want)
}
parsed, err := idToNumbers(got)
if err != nil {
t.Errorf("idToNumbers(%q) failed: %v", got, err)
continue
}
if len(parsed) != len(tc.numbers) {
t.Errorf("Roundtrip failed: got %v, want %v", parsed, tc.numbers)
}
}
}
func TestPositionToKey(t *testing.T) {
if got := PositionToKey(2, 1); got != "--0" {
t.Errorf("PositionToKey(2, 1) = %q, want %q", got, "--0")
}
if got := PositionToKey(1, 1); got != "0" {
t.Errorf("PositionToKey(1, 1) = %q, want %q", got, "0")
}
}