feat: implement lseq for golang
This commit is contained in:
parent
3eef15ba0b
commit
8104c24016
7 changed files with 575 additions and 0 deletions
44
golang/lseq_test.go
Normal file
44
golang/lseq_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue