-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase64_test.go
58 lines (49 loc) · 877 Bytes
/
base64_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package niceID
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestEncodeBase62(t *testing.T) {
t.Parallel()
testCases := []struct {
id int64
expected string
}{
{0, "0"},
{1, "1"},
{9, "9"},
{10, "A"},
{11, "B"},
{61, "z"},
{40346747266, "base62"},
{1337, "Kv"},
}
for _, testCase := range testCases {
assert.Equal(t, testCase.expected, EncodeBase64(testCase.id))
}
}
func BenchmarkEncodeBase62(b *testing.B) {
for i := 0; i < b.N; i++ {
EncodeBase64(int64(i))
}
}
func TestDecodeBase62(t *testing.T) {
t.Parallel()
testCases := []struct {
id string
expected int64
}{
{"0", 0},
{"1", 1},
{"9", 9},
{"A", 10},
{"B", 11},
{"z", 61},
{"Fe", 1000},
{"base62", 40346747266},
{"Kv", 1337},
}
for _, testCase := range testCases {
assert.Equal(t, testCase.expected, DecodeBase62(testCase.id))
}
}