-
Notifications
You must be signed in to change notification settings - Fork 99
/
converter_test.go
99 lines (85 loc) · 1.72 KB
/
converter_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
package avro
import (
"bytes"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLongConverter(t *testing.T) {
tests := []struct {
data []byte
typ Type
want int64
}{
{
data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0x07},
typ: Int,
want: 987654321,
},
}
for i, test := range tests {
test := test
t.Run(strconv.Itoa(i), func(t *testing.T) {
r := NewReader(bytes.NewReader(test.data), 10)
got := createLongConverter(test.typ)(r)
assert.Equal(t, test.want, got)
})
}
}
func TestFloatConverter(t *testing.T) {
tests := []struct {
data []byte
typ Type
want float32
}{
{
data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0x07},
typ: Int,
want: 987654321,
},
{
data: []byte{0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01},
typ: Long,
want: 9223372036854775807,
},
}
for i, test := range tests {
test := test
t.Run(strconv.Itoa(i), func(t *testing.T) {
r := NewReader(bytes.NewReader(test.data), 10)
got := createFloatConverter(test.typ)(r)
assert.Equal(t, test.want, got)
})
}
}
func TestDoubleConverter(t *testing.T) {
tests := []struct {
data []byte
typ Type
want float64
}{
{
data: []byte{0xE2, 0xA2, 0xF3, 0xAD, 0x07},
typ: Int,
want: 987654321,
},
{
data: []byte{0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01},
typ: Long,
want: 9223372036854775807,
},
{
data: []byte{0x62, 0x20, 0x71, 0x49},
typ: Float,
want: float64(float32(987654.124)),
},
}
for i, test := range tests {
test := test
t.Run(strconv.Itoa(i), func(t *testing.T) {
r := NewReader(bytes.NewReader(test.data), 10)
got := createDoubleConverter(test.typ)(r)
assert.Equal(t, test.want, got)
})
}
}