-
Notifications
You must be signed in to change notification settings - Fork 0
/
primitive_test.go
100 lines (86 loc) · 1.85 KB
/
primitive_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
package main
import (
"math"
"os"
"strconv"
"testing"
)
func TestByteArray(t *testing.T) {
data, err := os.ReadFile("testdata/pandas/tiny_byte_array.parquet")
if err != nil {
t.Fatal(err)
}
f := newFile(data)
if f.NumRows() != 10 {
t.Fatal("Wrong length")
}
structs := make([]s, f.NumRows())
parse(f, structs)
for i, s := range structs {
if string(s.TestBytes) != strconv.Itoa(i) {
t.Fatalf("Wrong at %d", i)
}
}
}
func TestFloat(t *testing.T) {
data, err := os.ReadFile("testdata/pandas/tiny_float.parquet")
if err != nil {
t.Fatal(err)
}
f := newFile(data)
if f.NumRows() != 10 {
t.Fatal("Wrong length")
}
structs := make([]s, f.NumRows())
parse(f, structs)
for i, s := range structs {
if s.TestFloat != float64(i) {
t.Fatalf("Wrong at %d", i)
}
}
}
func f64Equal(f1, f2 float64) bool {
if f1 == f2 {
return true
}
return math.IsNaN(f1) && math.IsNaN(f2)
}
func TestFloatWithNaN(t *testing.T) {
data, err := os.ReadFile("testdata/pandas/float_with_nan.parquet")
if err != nil {
t.Fatal(err)
}
f := newFile(data)
if f.NumRows() != 4 {
t.Fatal("Wrong length")
}
structs := make([]s, f.NumRows())
parse(f, structs)
expected := []float64{1, math.NaN(), 2, math.NaN()}
for i, s := range structs {
if !f64Equal(s.TestFloat, expected[i]) {
t.Fatalf("Wrong at %d, wanted %v, got %v", i, expected[i], s.TestFloat)
}
}
}
func TestInt(t *testing.T) {
for _, f := range []string{"testdata/pandas/tiny_int.parquet", "testdata/pandas/tiny_int.snappy.parquet"} {
t.Run(f, func(t *testing.T) {
data, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
f := newFile(data)
if f.NumRows() != 10 {
t.Fatal("Wrong length")
}
structs := make([]s, f.NumRows())
parse(f, structs)
for i, s := range structs {
if s.TestInt != int64(i) {
t.Fatalf("Wrong at %d", i)
}
}
})
}
}