-
Notifications
You must be signed in to change notification settings - Fork 2
/
streamer_float_test.go
98 lines (92 loc) · 1.9 KB
/
streamer_float_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
package jzon
import (
"math"
"testing"
"github.com/stretchr/testify/require"
)
func TestStreamer_Float32_Error(t *testing.T) {
t.Run("chain", func(t *testing.T) {
testStreamerChainError(t, func(s *Streamer) {
s.Float32(1)
})
})
t.Run("infinity", func(t *testing.T) {
f := float32(math.Inf(0))
s := NewStreamer()
defer s.Release()
s.Float32(f)
require.Equal(t, ErrFloatIsInfinity, s.Error)
})
t.Run("nan", func(t *testing.T) {
f := float32(math.NaN())
s := NewStreamer()
defer s.Release()
s.Float32(f)
require.Equal(t, ErrFloatIsNan, s.Error)
})
}
func TestStreamer_Float32(t *testing.T) {
f := func(t *testing.T, f float32) {
checkEncodeWithStandard(t, f, func(s *Streamer) {
s.Float32(f)
}, nil)
}
t.Run("1.2e-3", func(t *testing.T) {
f(t, 1.2e-3)
})
t.Run("1e-7", func(t *testing.T) {
f(t, 1e-7)
})
t.Run("1e21", func(t *testing.T) {
f(t, 1e21)
})
t.Run("-1e-7", func(t *testing.T) {
f(t, -1e-7)
})
t.Run("-1e21", func(t *testing.T) {
f(t, -1e21)
})
}
func TestStreamer_Float64_Error(t *testing.T) {
t.Run("chain", func(t *testing.T) {
testStreamerChainError(t, func(s *Streamer) {
s.Float64(1)
})
})
t.Run("infinity", func(t *testing.T) {
f := math.Inf(0)
s := NewStreamer()
defer s.Release()
s.Float64(f)
require.Equal(t, ErrFloatIsInfinity, s.Error)
})
t.Run("nan", func(t *testing.T) {
f := math.NaN()
s := NewStreamer()
defer s.Release()
s.Float64(f)
require.Equal(t, ErrFloatIsNan, s.Error)
})
}
func TestStreamer_Float64(t *testing.T) {
f := func(t *testing.T, f float64) {
checkEncodeWithStandard(t, f, func(s *Streamer) {
s.Float64(f)
}, nil)
}
t.Run("1.2e-3", func(t *testing.T) {
f(t, 1.2e-3)
})
t.Run("1e-7", func(t *testing.T) {
f(t, 1e-7)
})
t.Run("1e21", func(t *testing.T) {
f(t, 1e21)
})
t.Run("-1e-7", func(t *testing.T) {
f(t, -1e-7)
})
t.Run("-1e21", func(t *testing.T) {
f(t, -1e21)
})
}