-
Notifications
You must be signed in to change notification settings - Fork 46
/
runlengthbytereader_test.go
77 lines (72 loc) · 1.49 KB
/
runlengthbytereader_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
package orc
import (
"bytes"
"io"
"reflect"
"testing"
)
func TestRunLengthByteReader(t *testing.T) {
testCases := []struct {
input []byte
expect func([]byte)
}{
{
input: []byte{0x61, 0x00},
expect: func(output []byte) {
if len(output) != 100 {
t.Errorf("Test failed, expected len 100 but got %v", len(output))
}
for _, val := range output {
if val != 0 {
t.Errorf("Test failed, expected %v to equal %v", val, 0)
}
}
},
},
{
input: []byte{0x01, 0x01},
expect: func(output []byte) {
if len(output) != 4 {
t.Errorf("Test failed, expected len 100 but got %v", len(output))
}
for _, val := range output {
if val != 1 {
t.Errorf("Test failed, expected %v to equal %v", val, 0)
}
}
},
},
{
input: []byte{0xfe, 0x44, 0x45},
expect: func(output []byte) {
if !reflect.DeepEqual([]byte{0x44, 0x45}, output) {
t.Errorf("Test failed, got %v", output)
}
},
},
}
for _, tc := range testCases {
bs := NewRunLengthByteReader(bytes.NewReader(tc.input))
var output []byte
for bs.Next() {
b := bs.Byte()
output = append(output, b)
}
if err := bs.Err(); err != nil && err != io.EOF {
t.Fatal(err)
}
tc.expect(output)
}
}
func BenchmarkRunLengthByteReader(b *testing.B) {
input := bytes.Repeat([]byte{0x61, 0x00}, b.N)
bs := NewRunLengthByteReader(bytes.NewReader(input))
b.ResetTimer()
for i := 0; i < b.N; i++ {
if bs.Next() {
bs.Byte()
} else {
break
}
}
}