-
Notifications
You must be signed in to change notification settings - Fork 3
/
casters_number_x_test.go
114 lines (103 loc) · 2.92 KB
/
casters_number_x_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
package cast
import "testing"
func TestCastersNumberX_IntsUints(t *testing.T) {
for i := 0; i <= 1; i++ {
ints := []any{int(i), int8(i), int16(i), int32(i), int64(i)}
for _, v := range ints {
TestAssert(v, uint(i), t)
TestAssert(v, uint8(i), t)
TestAssert(v, uint16(i), t)
TestAssert(v, uint32(i), t)
TestAssert(v, uint64(i), t)
}
}
for i := 0; i <= 1; i++ {
uints := []any{uint(i), uint8(i), uint16(i), uint32(i), uint64(i)}
for _, v := range uints {
TestAssert(v, int(i), t)
TestAssert(v, int8(i), t)
TestAssert(v, int16(i), t)
TestAssert(v, int32(i), t)
TestAssert(v, int64(i), t)
}
}
}
func TestCastersNumberX_IntsFloats(t *testing.T) {
for i := 0; i <= 1; i++ {
ints := []any{int(i), int8(i), int16(i), int32(i), int64(i)}
for _, v := range ints {
TestAssert(v, float32(i), t)
TestAssert(v, float64(i), t)
}
}
for i := 0; i <= 1; i++ {
floats := []any{float32(i), float64(i)}
for _, v := range floats {
TestAssert(v, int(i), t)
TestAssert(v, int8(i), t)
TestAssert(v, int16(i), t)
TestAssert(v, int32(i), t)
TestAssert(v, int64(i), t)
}
}
}
func TestCastersNumberX_FloatsComplexes(t *testing.T) {
for i := float64(-1); i <= 1; i += 0.5 {
floats := []any{float32(i), float64(i)}
for _, v := range floats {
TestAssert(v, complex64(complex(i, 0)), t)
TestAssert(v, complex128(complex(i, 0)), t)
}
}
for i := float64(-1); i <= 1; i += 0.5 {
for j := float64(-1); j <= 1; j += 0.5 {
complexes := []any{complex64(complex(i, j)), complex128(complex(i, j))}
for _, v := range complexes {
TestAssert(v, float32(i), t)
TestAssert(v, float64(i), t)
}
}
}
}
func TestCastersNumberX_IntsComplexes(t *testing.T) {
for i := -1; i <= 1; i++ {
ints := []any{int(i), int8(i), int16(i), int32(i), int64(i)}
for _, v := range ints {
TestAssert(v, complex64(complex(float64(i), 0)), t)
TestAssert(v, complex128(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{complex64(complex(i, j)), complex128(complex(i, j))}
for _, v := range complexes {
TestAssert(v, int(i), t)
TestAssert(v, int8(i), t)
TestAssert(v, int16(i), t)
TestAssert(v, int32(i), t)
TestAssert(v, int64(i), t)
}
}
}
}
func TestCastersNumberX_UintsComplexes(t *testing.T) {
for i := 0; i <= 1; i++ {
uints := []any{uint(i), uint8(i), uint16(i), uint32(i), uint64(i)}
for _, v := range uints {
TestAssert(v, complex64(complex(float64(i), 0)), t)
TestAssert(v, complex128(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{complex64(complex(i, j)), complex128(complex(i, j))}
for _, v := range complexes {
TestAssert(v, uint(i), t)
TestAssert(v, uint8(i), t)
TestAssert(v, uint16(i), t)
TestAssert(v, uint32(i), t)
TestAssert(v, uint64(i), t)
}
}
}
}