-
Notifications
You must be signed in to change notification settings - Fork 7
/
convert_asUint_test.go
181 lines (155 loc) · 2.98 KB
/
convert_asUint_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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package generic
import "testing"
func TestAsUintInt(t *testing.T) {
i := int(100)
asUintTest(i, t)
}
func TestAsUintIntMinus(t *testing.T) {
x := int(-100)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintInt8(t *testing.T) {
i := int8(100)
asUintTest(i, t)
}
func TestAsUintInt8Minus(t *testing.T) {
x := int8(-100)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintInt16(t *testing.T) {
i := int16(100)
asUintTest(i, t)
}
func TestAsUintInt16Minus(t *testing.T) {
x := int16(-100)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintInt32(t *testing.T) {
i := int32(100)
asUintTest(i, t)
}
func TestAsUintInt32Minus(t *testing.T) {
x := int32(-100)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintInt64(t *testing.T) {
i := int64(100)
asUintTest(i, t)
}
func TestAsUintInt64Minus(t *testing.T) {
x := int64(-100)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintUint(t *testing.T) {
u := uint(100)
asUintTest(u, t)
}
func TestAsUintUint8(t *testing.T) {
u := uint8(100)
asUintTest(u, t)
}
func TestAsUintUint16(t *testing.T) {
u := uint16(100)
asUintTest(u, t)
}
func TestAsUintUint32(t *testing.T) {
u := uint32(100)
asUintTest(u, t)
}
func TestAsUintUint64(t *testing.T) {
u := uint64(100)
asUintTest(u, t)
}
func TestAsUintFloat32(t *testing.T) {
f := float32(100.001)
asUintTest(f, t)
}
func TestAsUintFloat32Minus(t *testing.T) {
x := float32(-100.001)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintFloat64(t *testing.T) {
f := float64(100.001)
asUintTest(f, t)
}
func TestAsUintFloat64Minus(t *testing.T) {
x := float64(-100.001)
_, _, err := asUint(x)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintTrue(t *testing.T) {
b := true
r, v, err := asUint(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 TestAsUintFalse(t *testing.T) {
b := false
r, v, err := asUint(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 TestAsUintNumericString(t *testing.T) {
s := "100"
asUintTest(s, t)
}
func TestAsUintUnumericString(t *testing.T) {
s := "abd.01"
_, _, err := asUint(s)
if err == nil {
t.Error("Expected error")
}
}
func TestAsUintInvalidType(t *testing.T) {
bs := []byte("100")
_, _, err := asUint(bs)
if err == nil {
t.Error("Expected error")
}
}
func asUintTest(x interface{}, t *testing.T) {
r, v, err := asUint(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: %v", r)
}
}