abcex/abcex_test.go
Arnas Udovic 1fd8a22846
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
support 36 and 64 base
2025-01-06 20:57:22 +02:00

55 lines
979 B
Go

package abcex
import (
"testing"
)
func TestConvert(t *testing.T) {
if Convert("9ix", BASE36, BASE62) != "3D7" {
t.Fatal("Failed conversion")
}
}
func TestEncode36(t *testing.T) {
if Encode(12345, BASE36) != "9ix" {
t.Fatal("Failed encoding")
}
}
func TestDecode36(t *testing.T) {
if Decode("9ix", BASE36) != 12345 {
t.Fatal("Failed decoding")
}
}
func TestEncode(t *testing.T) {
if Encode(12345, BASE62) != "3D7" {
t.Fatal("Failed encoding")
}
}
func TestDecode(t *testing.T) {
if Decode("3D7", BASE62) != 12345 {
t.Fatal("Failed decoding")
}
}
func TestZero(t *testing.T) {
if Encode(0, BASE62) != "0" {
t.Fatal("Failed zero encoding")
}
if Decode("0", BASE62) != 0 {
t.Fatal("Failed zero decoding")
}
}
func TestNegative(t *testing.T) {
if Encode(-20, BASE62) != "-K" {
t.Fatal("Failed negative encoding:", Encode(-20, BASE62))
}
if Decode("-ab", BASE62) != -2269 {
t.Fatal("Failed negative decoding", Decode("-ab", BASE62))
}
}