-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert_asInt_test.go
125 lines (106 loc) · 2.01 KB
/
convert_asInt_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
113
114
115
116
117
118
119
120
121
122
123
124
125
package generic
import "testing"
func TestAsIntInt(t *testing.T) {
i := int(100)
asIntTest(i, t)
}
func TestAsIntInt8(t *testing.T) {
i := int8(100)
asIntTest(i, t)
}
func TestAsIntInt16(t *testing.T) {
i := int16(100)
asIntTest(i, t)
}
func TestAsIntInt32(t *testing.T) {
i := int32(100)
asIntTest(i, t)
}
func TestAsIntInt64(t *testing.T) {
i := int64(100)
asIntTest(i, t)
}
func TestAsIntUint(t *testing.T) {
u := uint(100)
asIntTest(u, t)
}
func TestAsIntUint8(t *testing.T) {
u := uint8(100)
asIntTest(u, t)
}
func TestAsIntUint16(t *testing.T) {
u := uint16(100)
asIntTest(u, t)
}
func TestAsIntUint32(t *testing.T) {
u := uint32(100)
asIntTest(u, t)
}
func TestAsIntUint64(t *testing.T) {
u := uint64(100)
asIntTest(u, t)
}
func TestAsIntFloat32(t *testing.T) {
f := float32(100.0001)
asIntTest(f, t)
}
func TestAsIntFloat64(t *testing.T) {
f := float64(100.0001)
asIntTest(f, t)
}
func TestAsIntTrue(t *testing.T) {
b := true
r, v, err := asInt(b)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if r != 1 {
t.Errorf("expected: 1, actual: %d", r)
}
}
func TestAsIntFalse(t *testing.T) {
b := false
r, v, err := asInt(b)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if r != 0 {
t.Errorf("expected: 0, actual: %d", r)
}
}
func TestAsIntNumericString(t *testing.T) {
s := "100"
asIntTest(s, t)
}
func TestAsIntUnumericString(t *testing.T) {
s := "abd"
_, _, err := asInt(s)
if err == nil {
t.Error("Expected error")
}
}
func TestAsIntInvalidType(t *testing.T) {
bs := []byte("1")
_, _, err := asInt(bs)
if err == nil {
t.Error("Expected error")
}
}
func asIntTest(x interface{}, t *testing.T) {
r, v, err := asInt(x)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if r != 100 {
t.Errorf("expected: 100, actual: %d", r)
}
}