xmath.gen_test.gno
9.19 Kb ยท 466 lines
1package xmath
2
3import "testing"
4
5func TestInt8Helpers(t *testing.T) {
6 // Test MaxInt8
7 if MaxInt8(1, 2) != 2 {
8 t.Error("MaxInt8(1, 2) should be 2")
9 }
10 if MaxInt8(-1, -2) != -1 {
11 t.Error("MaxInt8(-1, -2) should be -1")
12 }
13
14 // Test MinInt8
15 if MinInt8(1, 2) != 1 {
16 t.Error("MinInt8(1, 2) should be 1")
17 }
18 if MinInt8(-1, -2) != -2 {
19 t.Error("MinInt8(-1, -2) should be -2")
20 }
21
22 // Test ClampInt8
23 if ClampInt8(5, 1, 3) != 3 {
24 t.Error("ClampInt8(5, 1, 3) should be 3")
25 }
26 if ClampInt8(0, 1, 3) != 1 {
27 t.Error("ClampInt8(0, 1, 3) should be 1")
28 }
29 if ClampInt8(2, 1, 3) != 2 {
30 t.Error("ClampInt8(2, 1, 3) should be 2")
31 }
32
33 // Test AbsInt8
34 if AbsInt8(-5) != 5 {
35 t.Error("AbsInt8(-5) should be 5")
36 }
37 if AbsInt8(5) != 5 {
38 t.Error("AbsInt8(5) should be 5")
39 }
40
41 // Test SignInt8
42 if SignInt8(-5) != -1 {
43 t.Error("SignInt8(-5) should be -1")
44 }
45 if SignInt8(5) != 1 {
46 t.Error("SignInt8(5) should be 1")
47 }
48 if SignInt8(0) != 0 {
49 t.Error("SignInt8(0) should be 0")
50 }
51
52}
53
54func TestInt16Helpers(t *testing.T) {
55 // Test MaxInt16
56 if MaxInt16(1, 2) != 2 {
57 t.Error("MaxInt16(1, 2) should be 2")
58 }
59 if MaxInt16(-1, -2) != -1 {
60 t.Error("MaxInt16(-1, -2) should be -1")
61 }
62
63 // Test MinInt16
64 if MinInt16(1, 2) != 1 {
65 t.Error("MinInt16(1, 2) should be 1")
66 }
67 if MinInt16(-1, -2) != -2 {
68 t.Error("MinInt16(-1, -2) should be -2")
69 }
70
71 // Test ClampInt16
72 if ClampInt16(5, 1, 3) != 3 {
73 t.Error("ClampInt16(5, 1, 3) should be 3")
74 }
75 if ClampInt16(0, 1, 3) != 1 {
76 t.Error("ClampInt16(0, 1, 3) should be 1")
77 }
78 if ClampInt16(2, 1, 3) != 2 {
79 t.Error("ClampInt16(2, 1, 3) should be 2")
80 }
81
82 // Test AbsInt16
83 if AbsInt16(-5) != 5 {
84 t.Error("AbsInt16(-5) should be 5")
85 }
86 if AbsInt16(5) != 5 {
87 t.Error("AbsInt16(5) should be 5")
88 }
89
90 // Test SignInt16
91 if SignInt16(-5) != -1 {
92 t.Error("SignInt16(-5) should be -1")
93 }
94 if SignInt16(5) != 1 {
95 t.Error("SignInt16(5) should be 1")
96 }
97 if SignInt16(0) != 0 {
98 t.Error("SignInt16(0) should be 0")
99 }
100
101}
102
103func TestInt32Helpers(t *testing.T) {
104 // Test MaxInt32
105 if MaxInt32(1, 2) != 2 {
106 t.Error("MaxInt32(1, 2) should be 2")
107 }
108 if MaxInt32(-1, -2) != -1 {
109 t.Error("MaxInt32(-1, -2) should be -1")
110 }
111
112 // Test MinInt32
113 if MinInt32(1, 2) != 1 {
114 t.Error("MinInt32(1, 2) should be 1")
115 }
116 if MinInt32(-1, -2) != -2 {
117 t.Error("MinInt32(-1, -2) should be -2")
118 }
119
120 // Test ClampInt32
121 if ClampInt32(5, 1, 3) != 3 {
122 t.Error("ClampInt32(5, 1, 3) should be 3")
123 }
124 if ClampInt32(0, 1, 3) != 1 {
125 t.Error("ClampInt32(0, 1, 3) should be 1")
126 }
127 if ClampInt32(2, 1, 3) != 2 {
128 t.Error("ClampInt32(2, 1, 3) should be 2")
129 }
130
131 // Test AbsInt32
132 if AbsInt32(-5) != 5 {
133 t.Error("AbsInt32(-5) should be 5")
134 }
135 if AbsInt32(5) != 5 {
136 t.Error("AbsInt32(5) should be 5")
137 }
138
139 // Test SignInt32
140 if SignInt32(-5) != -1 {
141 t.Error("SignInt32(-5) should be -1")
142 }
143 if SignInt32(5) != 1 {
144 t.Error("SignInt32(5) should be 1")
145 }
146 if SignInt32(0) != 0 {
147 t.Error("SignInt32(0) should be 0")
148 }
149
150}
151
152func TestInt64Helpers(t *testing.T) {
153 // Test MaxInt64
154 if MaxInt64(1, 2) != 2 {
155 t.Error("MaxInt64(1, 2) should be 2")
156 }
157 if MaxInt64(-1, -2) != -1 {
158 t.Error("MaxInt64(-1, -2) should be -1")
159 }
160
161 // Test MinInt64
162 if MinInt64(1, 2) != 1 {
163 t.Error("MinInt64(1, 2) should be 1")
164 }
165 if MinInt64(-1, -2) != -2 {
166 t.Error("MinInt64(-1, -2) should be -2")
167 }
168
169 // Test ClampInt64
170 if ClampInt64(5, 1, 3) != 3 {
171 t.Error("ClampInt64(5, 1, 3) should be 3")
172 }
173 if ClampInt64(0, 1, 3) != 1 {
174 t.Error("ClampInt64(0, 1, 3) should be 1")
175 }
176 if ClampInt64(2, 1, 3) != 2 {
177 t.Error("ClampInt64(2, 1, 3) should be 2")
178 }
179
180 // Test AbsInt64
181 if AbsInt64(-5) != 5 {
182 t.Error("AbsInt64(-5) should be 5")
183 }
184 if AbsInt64(5) != 5 {
185 t.Error("AbsInt64(5) should be 5")
186 }
187
188 // Test SignInt64
189 if SignInt64(-5) != -1 {
190 t.Error("SignInt64(-5) should be -1")
191 }
192 if SignInt64(5) != 1 {
193 t.Error("SignInt64(5) should be 1")
194 }
195 if SignInt64(0) != 0 {
196 t.Error("SignInt64(0) should be 0")
197 }
198
199}
200
201func TestIntHelpers(t *testing.T) {
202 // Test MaxInt
203 if MaxInt(1, 2) != 2 {
204 t.Error("MaxInt(1, 2) should be 2")
205 }
206 if MaxInt(-1, -2) != -1 {
207 t.Error("MaxInt(-1, -2) should be -1")
208 }
209
210 // Test MinInt
211 if MinInt(1, 2) != 1 {
212 t.Error("MinInt(1, 2) should be 1")
213 }
214 if MinInt(-1, -2) != -2 {
215 t.Error("MinInt(-1, -2) should be -2")
216 }
217
218 // Test ClampInt
219 if ClampInt(5, 1, 3) != 3 {
220 t.Error("ClampInt(5, 1, 3) should be 3")
221 }
222 if ClampInt(0, 1, 3) != 1 {
223 t.Error("ClampInt(0, 1, 3) should be 1")
224 }
225 if ClampInt(2, 1, 3) != 2 {
226 t.Error("ClampInt(2, 1, 3) should be 2")
227 }
228
229 // Test AbsInt
230 if AbsInt(-5) != 5 {
231 t.Error("AbsInt(-5) should be 5")
232 }
233 if AbsInt(5) != 5 {
234 t.Error("AbsInt(5) should be 5")
235 }
236
237 // Test SignInt
238 if SignInt(-5) != -1 {
239 t.Error("SignInt(-5) should be -1")
240 }
241 if SignInt(5) != 1 {
242 t.Error("SignInt(5) should be 1")
243 }
244 if SignInt(0) != 0 {
245 t.Error("SignInt(0) should be 0")
246 }
247
248}
249
250func TestUint8Helpers(t *testing.T) {
251 // Test MaxUint8
252 if MaxUint8(1, 2) != 2 {
253 t.Error("MaxUint8(1, 2) should be 2")
254 }
255
256 // Test MinUint8
257 if MinUint8(1, 2) != 1 {
258 t.Error("MinUint8(1, 2) should be 1")
259 }
260
261 // Test ClampUint8
262 if ClampUint8(5, 1, 3) != 3 {
263 t.Error("ClampUint8(5, 1, 3) should be 3")
264 }
265 if ClampUint8(0, 1, 3) != 1 {
266 t.Error("ClampUint8(0, 1, 3) should be 1")
267 }
268 if ClampUint8(2, 1, 3) != 2 {
269 t.Error("ClampUint8(2, 1, 3) should be 2")
270 }
271
272}
273
274func TestUint16Helpers(t *testing.T) {
275 // Test MaxUint16
276 if MaxUint16(1, 2) != 2 {
277 t.Error("MaxUint16(1, 2) should be 2")
278 }
279
280 // Test MinUint16
281 if MinUint16(1, 2) != 1 {
282 t.Error("MinUint16(1, 2) should be 1")
283 }
284
285 // Test ClampUint16
286 if ClampUint16(5, 1, 3) != 3 {
287 t.Error("ClampUint16(5, 1, 3) should be 3")
288 }
289 if ClampUint16(0, 1, 3) != 1 {
290 t.Error("ClampUint16(0, 1, 3) should be 1")
291 }
292 if ClampUint16(2, 1, 3) != 2 {
293 t.Error("ClampUint16(2, 1, 3) should be 2")
294 }
295
296}
297
298func TestUint32Helpers(t *testing.T) {
299 // Test MaxUint32
300 if MaxUint32(1, 2) != 2 {
301 t.Error("MaxUint32(1, 2) should be 2")
302 }
303
304 // Test MinUint32
305 if MinUint32(1, 2) != 1 {
306 t.Error("MinUint32(1, 2) should be 1")
307 }
308
309 // Test ClampUint32
310 if ClampUint32(5, 1, 3) != 3 {
311 t.Error("ClampUint32(5, 1, 3) should be 3")
312 }
313 if ClampUint32(0, 1, 3) != 1 {
314 t.Error("ClampUint32(0, 1, 3) should be 1")
315 }
316 if ClampUint32(2, 1, 3) != 2 {
317 t.Error("ClampUint32(2, 1, 3) should be 2")
318 }
319
320}
321
322func TestUint64Helpers(t *testing.T) {
323 // Test MaxUint64
324 if MaxUint64(1, 2) != 2 {
325 t.Error("MaxUint64(1, 2) should be 2")
326 }
327
328 // Test MinUint64
329 if MinUint64(1, 2) != 1 {
330 t.Error("MinUint64(1, 2) should be 1")
331 }
332
333 // Test ClampUint64
334 if ClampUint64(5, 1, 3) != 3 {
335 t.Error("ClampUint64(5, 1, 3) should be 3")
336 }
337 if ClampUint64(0, 1, 3) != 1 {
338 t.Error("ClampUint64(0, 1, 3) should be 1")
339 }
340 if ClampUint64(2, 1, 3) != 2 {
341 t.Error("ClampUint64(2, 1, 3) should be 2")
342 }
343
344}
345
346func TestUintHelpers(t *testing.T) {
347 // Test MaxUint
348 if MaxUint(1, 2) != 2 {
349 t.Error("MaxUint(1, 2) should be 2")
350 }
351
352 // Test MinUint
353 if MinUint(1, 2) != 1 {
354 t.Error("MinUint(1, 2) should be 1")
355 }
356
357 // Test ClampUint
358 if ClampUint(5, 1, 3) != 3 {
359 t.Error("ClampUint(5, 1, 3) should be 3")
360 }
361 if ClampUint(0, 1, 3) != 1 {
362 t.Error("ClampUint(0, 1, 3) should be 1")
363 }
364 if ClampUint(2, 1, 3) != 2 {
365 t.Error("ClampUint(2, 1, 3) should be 2")
366 }
367
368}
369
370func TestFloat32Helpers(t *testing.T) {
371 // Test MaxFloat32
372 if MaxFloat32(1, 2) != 2 {
373 t.Error("MaxFloat32(1, 2) should be 2")
374 }
375 if MaxFloat32(-1, -2) != -1 {
376 t.Error("MaxFloat32(-1, -2) should be -1")
377 }
378
379 // Test MinFloat32
380 if MinFloat32(1, 2) != 1 {
381 t.Error("MinFloat32(1, 2) should be 1")
382 }
383 if MinFloat32(-1, -2) != -2 {
384 t.Error("MinFloat32(-1, -2) should be -2")
385 }
386
387 // Test ClampFloat32
388 if ClampFloat32(5, 1, 3) != 3 {
389 t.Error("ClampFloat32(5, 1, 3) should be 3")
390 }
391 if ClampFloat32(0, 1, 3) != 1 {
392 t.Error("ClampFloat32(0, 1, 3) should be 1")
393 }
394 if ClampFloat32(2, 1, 3) != 2 {
395 t.Error("ClampFloat32(2, 1, 3) should be 2")
396 }
397
398 // Test AbsFloat32
399 if AbsFloat32(-5) != 5 {
400 t.Error("AbsFloat32(-5) should be 5")
401 }
402 if AbsFloat32(5) != 5 {
403 t.Error("AbsFloat32(5) should be 5")
404 }
405
406 // Test SignFloat32
407 if SignFloat32(-5) != -1 {
408 t.Error("SignFloat32(-5) should be -1")
409 }
410 if SignFloat32(5) != 1 {
411 t.Error("SignFloat32(5) should be 1")
412 }
413 if SignFloat32(0.0) != 0 {
414 t.Error("SignFloat32(0.0) should be 0")
415 }
416
417}
418
419func TestFloat64Helpers(t *testing.T) {
420 // Test MaxFloat64
421 if MaxFloat64(1, 2) != 2 {
422 t.Error("MaxFloat64(1, 2) should be 2")
423 }
424 if MaxFloat64(-1, -2) != -1 {
425 t.Error("MaxFloat64(-1, -2) should be -1")
426 }
427
428 // Test MinFloat64
429 if MinFloat64(1, 2) != 1 {
430 t.Error("MinFloat64(1, 2) should be 1")
431 }
432 if MinFloat64(-1, -2) != -2 {
433 t.Error("MinFloat64(-1, -2) should be -2")
434 }
435
436 // Test ClampFloat64
437 if ClampFloat64(5, 1, 3) != 3 {
438 t.Error("ClampFloat64(5, 1, 3) should be 3")
439 }
440 if ClampFloat64(0, 1, 3) != 1 {
441 t.Error("ClampFloat64(0, 1, 3) should be 1")
442 }
443 if ClampFloat64(2, 1, 3) != 2 {
444 t.Error("ClampFloat64(2, 1, 3) should be 2")
445 }
446
447 // Test AbsFloat64
448 if AbsFloat64(-5) != 5 {
449 t.Error("AbsFloat64(-5) should be 5")
450 }
451 if AbsFloat64(5) != 5 {
452 t.Error("AbsFloat64(5) should be 5")
453 }
454
455 // Test SignFloat64
456 if SignFloat64(-5) != -1 {
457 t.Error("SignFloat64(-5) should be -1")
458 }
459 if SignFloat64(5) != 1 {
460 t.Error("SignFloat64(5) should be 1")
461 }
462 if SignFloat64(0.0) != 0 {
463 t.Error("SignFloat64(0.0) should be 0")
464 }
465
466}