forked from reiver/go-cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfloat64_int32er_test.go
55 lines (46 loc) · 979 Bytes
/
float64_int32er_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
package cast
import (
"math"
"testing"
)
func TestFloat64FromInt32er(t *testing.T) {
tests := []struct{
Value int32er
Expected int32
}{
{
Value: testInt32erMin(),
Expected: math.MinInt32,
},
{
Value: testInt32erNegativeOne(),
Expected: -1,
},
{
Value: testInt32erZero(),
Expected: 0,
},
{
Value: testInt32erOne(),
Expected: 1,
},
{
Value: testInt32erMax(),
Expected: math.MaxInt32,
},
}
for testNumber, test := range tests {
x, err := Float64(test.Value)
if nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %v", testNumber, err, err)
continue
}
y := int32(x)
if expected, actual := test.Expected, y; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}
}