-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvarint_test.go
More file actions
57 lines (55 loc) · 1.04 KB
/
Copy pathvarint_test.go
File metadata and controls
57 lines (55 loc) · 1.04 KB
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
package moneroutil
import (
"bytes"
"testing"
)
func TestVarInt(t *testing.T) {
tests := []struct {
name string
varInt []byte
want uint64
}{
{
name: "1 byte",
varInt: []byte{0x01},
want: 1,
},
{
name: "3 bytes",
varInt: []byte{0x8f, 0xd6, 0x17},
want: 387855,
},
{
name: "4 bytes",
varInt: []byte{0x80, 0x92, 0xf4, 0x01},
want: 4000000,
},
{
name: "7 bytes",
varInt: []byte{0x80, 0xc0, 0xca, 0xf3, 0x84, 0xa3, 0x02},
want: 10000000000000,
},
}
var got uint64
var err error
var gotVarInt []byte
buf := new(bytes.Buffer)
for _, test := range tests {
gotVarInt = Uint64ToBytes(test.want)
if bytes.Compare(gotVarInt, test.varInt) != 0 {
t.Errorf("%s: varint want %x, got %x", test.name, test.varInt, gotVarInt)
continue
}
buf.Reset()
buf.Write(test.varInt)
got, err = ReadVarInt(buf)
if err != nil {
t.Errorf("%s: %s", test.name, err)
continue
}
if test.want != got {
t.Errorf("%s: want %d, got %d", test.name, test.want, got)
continue
}
}
}