-
Notifications
You must be signed in to change notification settings - Fork 7
/
int_encoding_test.go
51 lines (47 loc) · 962 Bytes
/
int_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
package surl
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIntEncoding(t *testing.T) {
tests := []struct {
name string
encoding intEncoding
input int64
want string
}{
{
name: "decimal",
encoding: stdIntEncoding(10),
input: 3507595200,
want: "3507595200",
},
{
name: "hex",
encoding: stdIntEncoding(16),
input: 3507595200,
want: "d111a7c0",
},
{
name: "base58",
encoding: &base58Encoding{},
input: 3507595200,
want: "6kXkRj",
},
{
name: "base64",
encoding: &base64Encoding{},
input: 3507595200,
want: "AAAAANERp8A",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.encoding.Encode(tt.input))
decoded, err := tt.encoding.Decode(tt.want)
require.NoError(t, err)
assert.Equal(t, tt.input, decoded)
})
}
}