-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathbooleanwriter_test.go
72 lines (67 loc) · 1.25 KB
/
booleanwriter_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
package orc
import (
"bytes"
"math/rand"
"reflect"
"testing"
)
func TestBooleanWriter(t *testing.T) {
testCases := []struct {
input []bool
expect func([]byte)
}{
{
input: []bool{true, false, false, false, false, false, false, false},
expect: func(output []byte) {
expected := []byte{0xff, 0x80}
if !reflect.DeepEqual(expected, output) {
t.Errorf("Test failed, expected %v to equal %v", output, expected)
}
},
},
}
for _, tc := range testCases {
var buf bytes.Buffer
w := NewBooleanWriter(&buf)
for i := range tc.input {
err := w.WriteBool(tc.input[i])
if err != nil {
t.Fatal(err)
}
}
err := w.Close()
if err != nil {
t.Fatal(err)
}
tc.expect(buf.Bytes())
}
}
func TestWriteReadBools(t *testing.T) {
var buf bytes.Buffer
w := NewBooleanWriter(&buf)
var input []bool
for i := 0; i < 100000; i++ {
var b bool
if rand.Intn(2) == 1 {
b = true
}
input = append(input, b)
err := w.WriteBool(b)
if err != nil {
t.Fatal(err)
}
}
err := w.Close()
if err != nil {
t.Fatal(err)
}
r := NewBooleanReader(&buf)
var index int
for r.Next() {
b := r.Bool()
if input[index] != b {
t.Errorf("Test failed, %v does not equal %v at index %v", b, input[index], index)
}
index++
}
}