-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcasters_bool_num_test.go
99 lines (90 loc) · 1.82 KB
/
casters_bool_num_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
package cast
import "testing"
func TestCastersBoolNum_BoolInts(t *testing.T) {
for i := 0; i <= 1; i++ {
var b bool
if i != 0 {
b = true
}
TestAssert(b, int(i), t)
TestAssert(b, int8(i), t)
TestAssert(b, int16(i), t)
TestAssert(b, int32(i), t)
TestAssert(b, int64(i), t)
}
for i := -1; i <= 1; i++ {
ints := []any{int(i), int8(i), int16(i), int32(i), int64(i)}
for _, v := range ints {
var b bool
if i != 0 {
b = true
}
TestAssert(v, b, t)
}
}
}
func TestCastersBoolNum_BoolUints(t *testing.T) {
for i := 0; i <= 1; i++ {
var b bool
if i != 0 {
b = true
}
TestAssert(b, uint(i), t)
TestAssert(b, uint8(i), t)
TestAssert(b, uint16(i), t)
TestAssert(b, uint32(i), t)
TestAssert(b, uint64(i), t)
}
for i := 0; i <= 1; i++ {
ints := []any{uint(i), uint8(i), uint16(i), uint32(i), uint64(i)}
for _, v := range ints {
var b bool
if i != 0 {
b = true
}
TestAssert(v, b, t)
}
}
}
func TestCastersBoolNum_BoolFloats(t *testing.T) {
for i := 0; i <= 1; i++ {
var b bool
if i != 0 {
b = true
}
TestAssert(b, float32(i), t)
TestAssert(b, float64(i), t)
}
for i := float64(-1); i <= 1; i += 0.5 {
ints := []any{float32(i), float64(i)}
for _, v := range ints {
var b bool
if i != 0 {
b = true
}
TestAssert(v, b, t)
}
}
}
func TestCastersBoolNum_BoolComplexes(t *testing.T) {
for i := 0; i <= 1; i++ {
var b bool
if i != 0 {
b = true
}
TestAssert(b, complex128(complex(float64(i), 0)), t)
TestAssert(b, complex64(complex(float64(i), 0)), t)
}
for i := float64(-1); i <= 1; i += 0.5 {
for j := float64(-1); j <= 1; j += 0.5 {
complexes := []any{complex128(complex(i, j)), complex64(complex(i, j))}
for _, v := range complexes {
var b bool
if i != 0 {
b = true
}
TestAssert(v, b, t)
}
}
}
}