-
Notifications
You must be signed in to change notification settings - Fork 3
/
decode_test.go
98 lines (94 loc) · 1.55 KB
/
decode_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
package fpc
import (
"reflect"
"testing"
)
func TestDecodeHeader(t *testing.T) {
type output struct {
n1, n2 uint8
p1, p2 predictorClass
}
testcases := []struct {
in byte
want pairHeader
}{
{
in: binstr2byte("01110111"),
want: pairHeader{
h1: header{
len: 8,
pType: 0,
},
h2: header{
len: 8,
pType: 0,
},
},
},
{
in: binstr2byte("11110111"),
want: pairHeader{
h1: header{
len: 8,
pType: 1,
},
h2: header{
len: 8,
pType: 0,
},
},
},
{
in: binstr2byte("00101111"),
want: pairHeader{
h1: header{
len: 2,
pType: 0,
},
h2: header{
len: 8,
pType: 1,
},
},
},
}
for i, tc := range testcases {
var have pairHeader
have.h1, have.h2 = decodeHeaders(tc.in)
if !reflect.DeepEqual(have, tc.want) {
t.Errorf("decodePrefix test=%d have=%+v want=%+v", i, have, tc.want)
}
}
}
func TestDecodeBlockHeader(t *testing.T) {
type result struct {
nRec int
nBytes int
}
testcases := []struct {
in []byte
want result
}{
{
in: []byte{0x00, 0x80, 0x00, 0xb6, 0x35, 0x02},
want: result{
nRec: 32768,
nBytes: 144822,
},
},
{
in: []byte{0x00, 0x80, 0x00, 0xc2, 0x43, 0x00},
want: result{
nRec: 32768,
nBytes: 17346,
},
},
}
for i, tc := range testcases {
var have result
have.nRec, have.nBytes = decodeBlockHeader(tc.in)
if !reflect.DeepEqual(have, tc.want) {
t.Errorf("decodeBlockHeader test=%d have=%+v want=%+v", i, have, tc.want)
}
}
}