-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathissue460_test.go
65 lines (60 loc) · 2.14 KB
/
issue460_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
/**
* Copyright 2023 ByteDance Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
* See the License for the specific language governing permissionsand
* limitations under the License.
*/
package issue_test
import (
`encoding/json`
`testing`
`github.com/bytedance/sonic`
`github.com/stretchr/testify/require`
)
// TODO: fix float32
func TestIssue460_UnmarshalMaxFloat32(t *testing.T) {
tests := []string {
// max.MaxFloat32
"3.40282346638528859811704183484516925440e+38",
// round up to max.MaxFloat32
// "3.402823469e+38",
"3.40282346e+38",
// "3.40282347e+38",
// "3.40282348e+38",
// "3.4028235e+38",
// TODO: fix this case
// "3.4028235677973366e+38", // Bits: 1000111111011111111111111111111111_10000000000000000000000000000
// overflow for float32, round up to max.MaxFloat32 + 1
"3.402823567797337e+38", // Bits: 1000111111011111111111111111111111_10000000000000000000000000001
"3.402823567797338e+38",
// "3.4028236e+38",
}
t.Run("max float32", func(t *testing.T) {
for _, data := range(tests) {
var f1, f2 float32
se := sonic.UnmarshalString(data, &f1)
je := json.Unmarshal([]byte(data), &f2)
require.Equal(t, se != nil, je != nil, data, se, je)
require.Equal(t, f2, f1, data)
}
})
t.Run("min float32", func(t *testing.T) {
for _, data := range(tests) {
data = string("-") + data
var f1, f2 float32
se := sonic.UnmarshalString(data, &f1)
je := json.Unmarshal([]byte(data), &f2)
require.Equal(t, se != nil, je != nil, data, se, je)
require.Equal(t, f2, f1, data)
}
})
}