-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumbers_test.go
63 lines (57 loc) · 1011 Bytes
/
numbers_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
package cbor
import (
"encoding/hex"
"testing"
"github.com/google/go-cmp/cmp"
)
func Test_shiftBytesInto(t *testing.T) {
tests := []struct {
got string
want uint64
}{
{
got: "00",
want: 0x00,
},
{
got: "0102030405060708",
want: 0x0102030405060708,
},
{
got: "01020304050607080910",
want: 0x0304050607080910,
},
}
for _, tt := range tests {
t.Run(tt.got, func(t *testing.T) {
got := shiftBytesInto[uint64](decodeHex(t, tt.got))
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Fatal(diff)
}
})
}
}
func Test_shiftBytesFrom(t *testing.T) {
tests := []struct {
got uint64
want string
}{
{
got: 0x00,
want: "0000000000000000",
},
{
got: 0x0102030405060708,
want: "0102030405060708",
},
}
for _, tt := range tests {
t.Run(tt.want, func(t *testing.T) {
got := make([]byte, 8)
shiftBytesFrom(tt.got, got)
if diff := cmp.Diff(tt.want, hex.EncodeToString(got)); diff != "" {
t.Fatal(diff)
}
})
}
}