-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathrunlengthintegerreader_test.go
77 lines (72 loc) · 1.59 KB
/
runlengthintegerreader_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"
"reflect"
"testing"
)
func progression(add int64) func(prev int64) int64 {
return func(prev int64) int64 {
return prev + add
}
}
func makeInt64Slice(start int64, fn func(prev int64) int64, l int) []int64 {
s := make([]int64, l)
var prev int64
prev, s[0] = start, start
for i := range s[1:] {
if fn != nil {
prev = fn(prev)
s[i+1] = prev
} else {
s[i+1] = start
}
}
return s
}
func TestRunLengthIntegerReader(t *testing.T) {
testCases := []struct {
signed bool
input []byte
expect func([]int64)
}{
{
signed: false,
input: []byte{0x61, 0x00, 0x07},
expect: func(output []int64) {
expected := makeInt64Slice(7, nil, 100)
if !reflect.DeepEqual(output, expected) {
t.Errorf("Test failed, expected %v to equal %v", output, expected)
}
},
},
{
signed: false,
input: []byte{0x61, 0xff, 0x64},
expect: func(output []int64) {
expected := makeInt64Slice(100, progression(-1), 100)
if !reflect.DeepEqual(output, expected) {
t.Errorf("Test failed, expected %v to equal %v", output, expected)
}
},
},
{
signed: false,
input: []byte{0xfb, 0x02, 0x03, 0x04, 0x07, 0xb},
expect: func(output []int64) {
expected := []int64{2, 3, 4, 7, 11}
if !reflect.DeepEqual(output, expected) {
t.Errorf("Test failed, expected %v to equal %v", output, expected)
}
},
},
}
for _, tc := range testCases {
r := NewRunLengthIntegerReader(bytes.NewReader(tc.input), tc.signed)
var output []int64
for r.Next() {
v := r.Int()
output = append(output, v)
}
tc.expect(output)
}
}