abcex/abcex_test.go

38 lines
586 B
Go
Raw Permalink Normal View History

2021-05-11 20:21:06 +00:00
package abcex
2024-08-08 11:53:11 +00:00
import (
"testing"
)
2021-05-11 20:21:06 +00:00
func TestEncode(t *testing.T) {
2024-08-08 15:25:21 +00:00
if Encode(12345) != "9ix" {
t.Fatal("Failed encoding")
}
2021-05-11 20:21:06 +00:00
}
func TestDecode(t *testing.T) {
2024-08-08 15:25:21 +00:00
if Decode("9ix") != 12345 {
t.Fatal("Failed decoding")
}
2024-08-08 11:53:11 +00:00
}
func TestZero(t *testing.T) {
2024-08-08 15:25:21 +00:00
if Encode(0) != "0" {
t.Fatal("Failed zero encoding")
}
2024-08-08 11:53:11 +00:00
2024-08-08 15:25:21 +00:00
if Decode("0") != 0 {
t.Fatal("Failed zero decoding")
}
}
func TestNegative(t *testing.T) {
if Encode(-20) != "-k" {
t.Fatal("Failed negative encoding:", Encode(-20))
}
if Decode("-ab") != -371 {
t.Fatal("Failed negative decoding", Decode("-ab"))
}
2021-05-11 20:21:06 +00:00
}