-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfloat64x3_test.go
209 lines (165 loc) · 4.27 KB
/
float64x3_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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package cast
import (
"math"
"testing"
)
func TestFloat64x3FromFloat32x3(t *testing.T) {
tests := []struct{
Value [3]float32
}{}
{
f32s := []float32{
float32(math.Inf(-1)),
-math.MaxFloat32,
-math.Pi,
-math.E,
-math.Sqrt2,
-1.0,
-math.Ln2,
-math.SmallestNonzeroFloat32,
0.0,
math.SmallestNonzeroFloat32,
math.Ln2,
1.0,
math.Sqrt2,
math.E,
math.Pi,
math.MaxFloat32,
float32(math.Inf(+1)),
float32(math.NaN()),
}
const numRand = 5
for i:=0; i<numRand; i++ {
f32 := randomness.Float32()
f32s = append(f32s, f32)
f32 = -randomness.Float32()
f32s = append(f32s, f32)
f32 = randomness.Float32() * math.MaxFloat32
f32s = append(f32s, f32)
f32 = -randomness.Float32() * math.MaxFloat32
f32s = append(f32s, f32)
f32 = randomness.Float32() * 999999999
f32s = append(f32s, f32)
f32 = -randomness.Float32() * 999999999
f32s = append(f32s, f32)
}
for _, x := range f32s {
for _, y := range f32s {
for _, z := range f32s {
test := struct{
Value [3]float32
}{
Value: [3]float32{x, y, z},
}
tests = append(tests, test)
}
}
}
}
for testNumber, test := range tests {
x, err := Float64x3(test.Value)
if nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %v", testNumber, err, err)
continue
}
y := [3]float32{float32(x[0]), float32(x[1]), float32(x[2])}
if expected, actual := test.Value[0], y[0]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
if expected, actual := test.Value[1], y[1]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
if expected, actual := test.Value[2], y[2]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}
}
func TestFloat64x3FromFloat64x3(t *testing.T) {
tests := []struct{
Value [3]float64
}{}
{
f64s := []float64{
math.Inf(-1),
-math.MaxFloat64,
-math.Pi,
-math.E,
-math.Sqrt2,
-1.0,
-math.Ln2,
-math.SmallestNonzeroFloat64,
0.0,
math.SmallestNonzeroFloat64,
math.Ln2,
1.0,
math.Sqrt2,
math.E,
math.Pi,
math.MaxFloat64,
math.Inf(+1),
math.NaN(),
}
const numRand = 5
for i:=0; i<numRand; i++ {
f64 := randomness.Float64()
f64s = append(f64s, f64)
f64 = -randomness.Float64()
f64s = append(f64s, f64)
f64 = randomness.Float64() * math.MaxFloat64
f64s = append(f64s, f64)
f64 = -randomness.Float64() * math.MaxFloat64
f64s = append(f64s, f64)
f64 = randomness.Float64() * 999999999
f64s = append(f64s, f64)
f64 = -randomness.Float64() * 999999999
f64s = append(f64s, f64)
}
for _, x := range f64s {
for _, y := range f64s {
for _, z := range f64s {
test := struct{
Value [3]float64
}{
Value: [3]float64{x, y, z},
}
tests = append(tests, test)
}
}
}
}
for testNumber, test := range tests {
x, err := Float64x3(test.Value)
if nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %v", testNumber, err, err)
continue
}
y := [3]float64(x)
if expected, actual := test.Value[0], y[0]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
if expected, actual := test.Value[1], y[1]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
if expected, actual := test.Value[2], y[2]; expected != actual {
if !(math.IsNaN(float64(expected)) && math.IsNaN(float64(actual))) {
t.Errorf("For test #%d, expected %v, but actually got %v.", testNumber, expected, actual)
continue
}
}
}
}