-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathrunlengthintegerwriter_test.go
107 lines (102 loc) · 2.18 KB
/
runlengthintegerwriter_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
package orc
import (
"bytes"
"math/rand"
// "reflect"
"testing"
)
func TestRunLengthIntegerWriter(t *testing.T) {
testCases := []struct {
signed bool
input []int64
expect func([]byte)
}{
// {
// signed: false,
// input: makeInt64Slice(7, nil, 100),
// expect: func(output []byte) {
// expected := []byte{0x61, 0xff, 0x64}
// if !reflect.DeepEqual(output, expected) {
// t.Errorf("Test failed, expected %v to equal %v", output, expected)
// }
// },
// },
// {
// signed: false,
// input: []int64{2, 3, 4, 7, 11},
// expect: func(output []byte) {
// expected := []byte{0xfb, 0x02, 0x03, 0x04, 0x07, 0xb}
// if !reflect.DeepEqual(output, expected) {
// t.Errorf("Test failed, expected %v to equal %v", output, expected)
// }
// },
// },
}
for _, tc := range testCases {
var buf bytes.Buffer
w := NewRunLengthIntegerWriter(&buf, tc.signed)
for i := range tc.input {
err := w.WriteInt(tc.input[i])
if err != nil {
t.Fatal(err)
}
}
err := w.Close()
if err != nil {
t.Fatal(err)
}
tc.expect(buf.Bytes())
}
}
func TestWriteReadRunLengthIntegerWriter(t *testing.T) {
var buf bytes.Buffer
w := NewRunLengthIntegerWriter(&buf, true)
var input []int64
for i := 0; i < 1000000; i++ {
b := rand.Int63n(1000000)
input = append(input, b)
err := w.WriteInt(b)
if err != nil {
t.Fatal(err)
}
}
err := w.Close()
if err != nil {
t.Fatal(err)
}
r := NewRunLengthIntegerReader(&buf, true)
var index int
for r.Next() {
b := r.Int()
if input[index] != b {
t.Errorf("Test failed, %v does not equal %v at index %v", b, input[index], index)
}
index++
}
}
func TestWriteReadRunLengthIntegerWriterRun(t *testing.T) {
var buf bytes.Buffer
w := NewRunLengthIntegerWriter(&buf, true)
var input []int64
for i := 0; i < 1000000; i++ {
b := rand.Int63n(2)
input = append(input, b)
err := w.WriteInt(b)
if err != nil {
t.Fatal(err)
}
}
err := w.Close()
if err != nil {
t.Fatal(err)
}
r := NewRunLengthIntegerReader(&buf, true)
var index int
for r.Next() {
b := r.Int()
if input[index] != b {
t.Errorf("Test failed, %v does not equal %v at index %v", b, input[index], index)
}
index++
}
}