feat: implement lseq for golang

This commit is contained in:
nobody 2025-12-12 23:18:05 -08:00
commit 8104c24016
Signed by: GrocerPublishAgent
GPG key ID: D460CD54A9E3AB86
7 changed files with 575 additions and 0 deletions

44
golang/lseq_test.go Normal file
View file

@ -0,0 +1,44 @@
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")
}
}