-
Notifications
You must be signed in to change notification settings - Fork 13
/
sizeof_test.go
125 lines (121 loc) · 1.81 KB
/
sizeof_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package csproto_test
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
"github.com/CrowdStrike/csproto"
)
func TestSizeOfVarint(t *testing.T) {
cases := []struct {
name string
v uint64
expected int
}{
{
name: "min value",
v: 1,
expected: 1,
},
{
name: "2^7-1",
v: (1 << 7) - 1,
expected: 1,
},
{
name: "2^7",
v: (1 << 7),
expected: 2,
},
{
name: "2^14-1",
v: (1 << 14) - 1,
expected: 2,
},
{
name: "2^14",
v: (1 << 14),
expected: 3,
},
{
name: "2^21-1",
v: (1 << 21) - 1,
expected: 3,
},
{
name: "2^21",
v: (1 << 21),
expected: 4,
},
{
name: "2^28-1",
v: (1 << 28) - 1,
expected: 4,
},
{
name: "2^28",
v: (1 << 28),
expected: 5,
},
{
name: "2^35-1",
v: (1 << 35) - 1,
expected: 5,
},
{
name: "2^35",
v: (1 << 35),
expected: 6,
},
{
name: "2^42-1",
v: (1 << 42) - 1,
expected: 6,
},
{
name: "2^42",
v: (1 << 42),
expected: 7,
},
{
name: "2^49-1",
v: (1 << 49) - 1,
expected: 7,
},
{
name: "2^49",
v: (1 << 49),
expected: 8,
},
{
name: "2^56-1",
v: (1 << 56) - 1,
expected: 8,
},
{
name: "2^56",
v: (1 << 56),
expected: 9,
},
{
name: "2^63-1",
v: (1 << 63) - 1,
expected: 9,
},
{
name: "2^63",
v: (1 << 63),
expected: 10,
},
{
name: "math.MaxUInt64",
v: math.MaxUint64,
expected: 10,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := csproto.SizeOfVarint(tc.v)
assert.Equal(t, tc.expected, got)
})
}
}