ID/encoder_test.go

39 lines
604 B
Go

package ID_test
import (
"testing"
"go.dedaa.de/julixau/ID"
)
// Verify that the Encoder works
func TestEncode(t *testing.T) {
totest := ID.Type(100)
str := totest.Encode()
if str != "ZAAA" {
t.Fail()
}
// encode a number that only fits in 3 bytes
totest = ID.Type(100000)
if totest.Encode() != "oIYB" {
t.Fail()
}
}
// Test the decoder against the Encoder
func TestDecode(t *testing.T) {
id := ID.Type(100000)
totest := id.Encode()
t.Log(id, totest)
if res, err := ID.Decode(totest); err != nil {
t.Fatal(err)
} else if res != id {
t.Fatal(res)
} else {
t.Log(res)
}
}