forked from qlik-oss/enigma-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat_test.go
47 lines (36 loc) · 1.22 KB
/
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
package enigma
import (
"encoding/json"
"github.com/stretchr/testify/assert"
"math"
"testing"
)
func TestFloat_UnmarshalJSON(t *testing.T) {
var cell NxCell
_ = json.Unmarshal([]byte(`{"qNum":"Infinity"}`), &cell)
assert.True(t, math.IsInf(float64(cell.Num), 1))
_ = json.Unmarshal([]byte(`{"qNum":"+Infinity"}`), &cell)
assert.True(t, math.IsInf(float64(cell.Num), 1))
_ = json.Unmarshal([]byte(`{"qNum":"-Infinity"}`), &cell)
assert.True(t, math.IsInf(float64(cell.Num), -1))
_ = json.Unmarshal([]byte(`{"qNum":"NaN"}`), &cell)
assert.True(t, math.IsNaN(float64(cell.Num)))
_ = json.Unmarshal([]byte(`{"qNum":-125}`), &cell)
assert.Equal(t, float64(-125), float64(cell.Num))
}
func TestFloat_MarshalJSON(t *testing.T) {
var cell NxCell
var result []byte
cell.Num = -125
result, _ = json.Marshal(&cell)
assert.Equal(t, `{"qNum":-125}`, string(result))
cell.Num = Float64(math.Inf(+1))
result, _ = json.Marshal(&cell)
assert.Equal(t, `{"qNum":"Infinity"}`, string(result))
cell.Num = Float64(math.Inf(-1))
result, _ = json.Marshal(&cell)
assert.Equal(t, `{"qNum":"-Infinity"}`, string(result))
cell.Num = Float64(math.NaN())
result, _ = json.Marshal(&cell)
assert.Equal(t, `{"qNum":"NaN"}`, string(result))
}