forked from reiver/go-cast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathint8_test.go
112 lines (94 loc) · 1.76 KB
/
int8_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package cast
import (
"math"
"testing"
)
func TestInt8FromInt8(t *testing.T) {
tests := []struct{
Value int8
}{
{
Value: math.MinInt8,
},
{
Value: -1,
},
{
Value: 0,
},
{
Value: 1,
},
{
Value: math.MaxInt8,
},
}
{
const numRand = 20
for i:=0; i<numRand; i++ {
test := struct{
Value int8
}{
Value: int8(randomness.Int63n(math.MaxInt8)),
}
tests = append(tests, test)
test = struct{
Value int8
}{
Value: -int8(randomness.Int63n(-1*math.MinInt8)),
}
tests = append(tests, test)
}
}
for testNumber, test := range tests {
x, err := Int8(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.Value, y; expected != actual {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}
func TestInt8FromInt8er(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 := Int8(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 {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}