-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_test.go
72 lines (66 loc) · 1.3 KB
/
encoding_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package snowfake_test
import (
"fmt"
"testing"
"github.com/deryrahman/snowfake"
)
func TestEncodeBase58(t *testing.T) {
name := func(id uint64) string {
return fmt.Sprintf("id=%d", id)
}
tests := []struct {
id uint64
expectedEncoded string
}{
{
id: uint64(18),
expectedEncoded: "j",
},
{
id: uint64(1577836800),
expectedEncoded: "3pqPUL",
},
{
id: 0xFFFFFFFFFFFFFFFF,
expectedEncoded: "JPwcyDCgEup",
},
}
for _, tt := range tests {
t.Run(name(tt.id), func(t *testing.T) {
encoded := snowfake.EncodeBase58(tt.id)
assertEqual(t, tt.expectedEncoded, encoded)
})
}
}
func TestDecodeBase58(t *testing.T) {
name := func(str string) string {
return fmt.Sprintf("str=%s", str)
}
tests := []struct {
str string
expectedDecoded uint64
}{
{
str: "j",
expectedDecoded: uint64(18),
},
{
str: "3pqPUL",
expectedDecoded: uint64(1577836800),
},
{
str: "JPwcyDCgEup",
expectedDecoded: 0xFFFFFFFFFFFFFFFF,
},
{
str: "3pqPU=",
expectedDecoded: 0,
},
}
for _, tt := range tests {
t.Run(name(tt.str), func(t *testing.T) {
decoded := snowfake.DecodeBase58(tt.str)
assertEqual(t, tt.expectedDecoded, decoded)
})
}
}