37 lines
586 B
Go
37 lines
586 B
Go
package abcex
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestEncode(t *testing.T) {
|
|
if Encode(12345) != "9ix" {
|
|
t.Fatal("Failed encoding")
|
|
}
|
|
}
|
|
|
|
func TestDecode(t *testing.T) {
|
|
if Decode("9ix") != 12345 {
|
|
t.Fatal("Failed decoding")
|
|
}
|
|
}
|
|
|
|
func TestZero(t *testing.T) {
|
|
if Encode(0) != "0" {
|
|
t.Fatal("Failed zero encoding")
|
|
}
|
|
|
|
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"))
|
|
}
|
|
}
|