-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfloat64_int8er_test.go
55 lines (46 loc) · 963 Bytes
/
float64_int8er_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 TestFloat64FromInt8er(t *testing.T) {
tests := []struct{
Value int8er
Expected int8
}{
{
Value: testInt8erMin(),
Expected: math.MinInt8,
},
{
Value: testInt8erNegativeOne(),
Expected: -1,
},
{
Value: testInt8erZero(),
Expected: 0,
},
{
Value: testInt8erOne(),
Expected: 1,
},
{
Value: testInt8erMax(),
Expected: math.MaxInt8,
},
}
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 := int8(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
}
}
}
}