-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvint_test.go
166 lines (162 loc) · 3.81 KB
/
vint_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package ebml
import (
"reflect"
"testing"
)
func Test_vintOctetLength(t *testing.T) {
tests := []struct {
name string
vint []byte
want int
}{
{
name: "1", vint: []byte{0x80}, want: 1,
},
{
name: "2", vint: []byte{0x40}, want: 2,
},
{
name: "7", vint: []byte{0x02}, want: 7,
},
{
name: "8", vint: []byte{0x01}, want: 8,
},
{
name: "9", vint: []byte{0x00, 0x80}, want: 9,
},
{
name: "10", vint: []byte{0x00, 0x40}, want: 10,
},
{
name: "15", vint: []byte{0x00, 0x02}, want: 15,
},
{
name: "16", vint: []byte{0x00, 0x01}, want: 16,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := vintOctetLength(tt.vint); got != tt.want {
t.Errorf("vintOctetLength() = %v, want %v", got, tt.want)
}
})
}
}
func Test_vintData(t *testing.T) {
type args struct {
b []byte
l int
}
tests := []struct {
name string
args args
want []byte
}{
{
name: "1 byte",
args: args{b: []byte{0x81}, l: 1},
want: []byte{0x01},
},
{
name: "2 byte",
args: args{b: []byte{0x41, 0x11}, l: 2},
want: []byte{0x01, 0x11},
},
{
name: "7 byte",
args: args{b: []byte{0x03, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 7},
want: []byte{0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
{
name: "8 byte",
args: args{b: []byte{0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 8},
want: []byte{0x00, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
{
name: "9 byte",
args: args{b: []byte{0x00, 0x81, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 9},
want: []byte{0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
{
name: "10 byte",
args: args{b: []byte{0x00, 0x41, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 10},
want: []byte{0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
{
name: "15 byte",
args: args{b: []byte{0x00, 0x03, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 15},
want: []byte{0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
{
name: "16 byte",
args: args{b: []byte{0x00, 0x01, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11}, l: 16},
want: []byte{0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := vintData(tt.args.b, tt.args.l); !reflect.DeepEqual(got, tt.want) {
t.Errorf("vintData() = %v, want %v", got, tt.want)
}
})
}
}
func Test_vintDataAllOne(t *testing.T) {
type args struct {
b []byte
l int
}
tests := []struct {
name string
args args
want bool
}{
{
name: "1 byte all 1",
args: args{b: []byte{0x7f}, l: 1},
want: true,
},
{
name: "1 byte not all 1",
args: args{b: []byte{0x70}, l: 1},
want: false,
},
{
name: "2 byte all 1",
args: args{b: []byte{0x3f, 0xff}, l: 2},
want: true,
},
{
name: "2 byte not all 1",
args: args{b: []byte{0x3f, 0xf0}, l: 2},
want: false,
},
{
name: "9 byte all 1",
args: args{b: []byte{0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, l: 9},
want: true,
},
{
name: "9 byte not all 1",
args: args{b: []byte{0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0}, l: 9},
want: false,
},
{
name: "10 byte all 1",
args: args{b: []byte{0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, l: 10},
want: true,
},
{
name: "10 byte not all 1",
args: args{b: []byte{0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0}, l: 10},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := vintDataAllOne(tt.args.b, tt.args.l); got != tt.want {
t.Errorf("vintDataAllOne() = %v, want %v", got, tt.want)
}
})
}
}