-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconvert_asFloat_test.go
143 lines (124 loc) · 2.49 KB
/
convert_asFloat_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
package generic
import "testing"
func TestAsFloatInt(t *testing.T) {
i := int(100)
asFloatTest(i, t)
}
func TestAsFloatInt8(t *testing.T) {
i := int8(100)
asFloatTest(i, t)
}
func TestAsFloatInt16(t *testing.T) {
i := int16(100)
asFloatTest(i, t)
}
func TestAsFloatInt32(t *testing.T) {
i := int32(100)
asFloatTest(i, t)
}
func TestAsFloatInt64(t *testing.T) {
i := int64(100)
asFloatTest(i, t)
}
func TestAsFloatUint(t *testing.T) {
u := uint(100)
asFloatTest(u, t)
}
func TestAsFloatUint8(t *testing.T) {
u := uint8(100)
asFloatTest(u, t)
}
func TestAsFloatUint16(t *testing.T) {
u := uint16(100)
asFloatTest(u, t)
}
func TestAsFloatUint32(t *testing.T) {
u := uint32(100)
asFloatTest(u, t)
}
func TestAsFloatUint64(t *testing.T) {
u := uint64(100)
asFloatTest(u, t)
}
func TestAsFloatFloat32(t *testing.T) {
f := float32(100.0001)
r, v, err := asFloat(f)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if float32(r) != 100.0001 {
t.Errorf("expected: 100.0001, actual: %v", r)
}
}
func TestAsFloatFloat64(t *testing.T) {
f := float64(100.0001)
r, v, err := asFloat(f)
if err != nil {
t.Errorf("Not Expected error. error:%s", err.Error())
}
if !v {
t.Error("expected: true, actual: false")
}
if r != 100.0001 {
t.Errorf("expected: 100, actual: %v", r)
}
}
func TestAsFloatTrue(t *testing.T) {
b := true
r, v, err := asFloat(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: %v", r)
}
}
func TestAsFloatFalse(t *testing.T) {
b := false
r, v, err := asFloat(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: %v", r)
}
}
func TestAsFloatNumericString(t *testing.T) {
s := "100"
asFloatTest(s, t)
}
func TestAsFloatUnumericString(t *testing.T) {
s := "abd"
_, _, err := asFloat(s)
if err == nil {
t.Error("Expected error")
}
}
func TestAsFloatInvalidType(t *testing.T) {
bs := []byte("1")
_, _, err := asFloat(bs)
if err == nil {
t.Error("Expected error")
}
}
func asFloatTest(x interface{}, t *testing.T) {
r, v, err := asFloat(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)
}
}