abcex/abcex_test.go

56 lines
979 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
2025-01-06 18:57:22 +00:00
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")
}
}
2021-05-11 20:21:06 +00:00
func TestEncode(t *testing.T) {
2025-01-06 18:57:22 +00:00
if Encode(12345, BASE62) != "3D7" {
2024-08-08 15:25:21 +00:00
t.Fatal("Failed encoding")
}
2021-05-11 20:21:06 +00:00
}
func TestDecode(t *testing.T) {
2025-01-06 18:57:22 +00:00
if Decode("3D7", BASE62) != 12345 {
2024-08-08 15:25:21 +00:00
t.Fatal("Failed decoding")
}
2024-08-08 11:53:11 +00:00
}
func TestZero(t *testing.T) {
2025-01-06 18:57:22 +00:00
if Encode(0, BASE62) != "0" {
2024-08-08 15:25:21 +00:00
t.Fatal("Failed zero encoding")
}
2024-08-08 11:53:11 +00:00
2025-01-06 18:57:22 +00:00
if Decode("0", BASE62) != 0 {
2024-08-08 15:25:21 +00:00
t.Fatal("Failed zero decoding")
}
}
func TestNegative(t *testing.T) {
2025-01-06 18:57:22 +00:00
if Encode(-20, BASE62) != "-K" {
t.Fatal("Failed negative encoding:", Encode(-20, BASE62))
2024-08-08 15:25:21 +00:00
}
2025-01-06 18:57:22 +00:00
if Decode("-ab", BASE62) != -2269 {
t.Fatal("Failed negative decoding", Decode("-ab", BASE62))
2024-08-08 15:25:21 +00:00
}
2021-05-11 20:21:06 +00:00
}