comparison tests/test_matrix.nim @ 212:77755701bf49

fix: tests
author Sam <sam@basx.dev>
date Tue, 09 May 2023 20:39:49 +0700
parents 8287a91e5d56
children 67081fbaf636
comparison
equal deleted inserted replaced
211:744285b47a4d 212:77755701bf49
1 import random 1 import random
2 import math 2 import math
3 3
4 import semicongine/math/vector 4 import semicongine
5 import semicongine/math/matrix
6 5
7 6
8 proc echoInfo(v: TVec) = 7 proc echoInfo(v: TVec) =
9 echo v 8 echo v
10 echo " Length: ", v.length 9 echo " Length: ", v.length
31 proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10)) 30 proc randVec4I(): auto = newVec4(rand(1 .. 10), rand(1 .. 10), rand(1 .. 10), rand(1 .. 10))
32 proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01) 31 proc randVec4F(): auto = newVec4(rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01, rand(10'f) + 0.01)
33 32
34 33
35 template withAllIntegerMats(stuff: untyped) = 34 template withAllIntegerMats(stuff: untyped) =
36 stuff(TMat22[int32]) 35 stuff(TMat2[int32])
37 stuff(TMat23[int32]) 36 stuff(TMat23[int32])
38 stuff(TMat32[int32]) 37 stuff(TMat32[int32])
39 stuff(TMat33[int32]) 38 stuff(TMat3[int32])
40 stuff(TMat34[int32]) 39 stuff(TMat34[int32])
41 stuff(TMat43[int32]) 40 stuff(TMat43[int32])
42 stuff(TMat44[int32]) 41 stuff(TMat4[int32])
43 stuff(TMat22[int64]) 42 stuff(TMat2[int64])
44 stuff(TMat23[int64]) 43 stuff(TMat23[int64])
45 stuff(TMat32[int64]) 44 stuff(TMat32[int64])
46 stuff(TMat33[int64]) 45 stuff(TMat3[int64])
47 stuff(TMat34[int64]) 46 stuff(TMat34[int64])
48 stuff(TMat43[int64]) 47 stuff(TMat43[int64])
49 stuff(TMat44[int64]) 48 stuff(TMat4[int64])
50 49
51 template withAllFloatMats(stuff: untyped) = 50 template withAllFloatMats(stuff: untyped) =
52 stuff(TMat22[float32]) 51 stuff(TMat2[float32])
53 stuff(TMat23[float32]) 52 stuff(TMat23[float32])
54 stuff(TMat32[float32]) 53 stuff(TMat32[float32])
55 stuff(TMat33[float32]) 54 stuff(TMat3[float32])
56 stuff(TMat34[float32]) 55 stuff(TMat34[float32])
57 stuff(TMat43[float32]) 56 stuff(TMat43[float32])
58 stuff(TMat44[float32]) 57 stuff(TMat4[float32])
59 stuff(TMat22[float64]) 58 stuff(TMat2[float64])
60 stuff(TMat23[float64]) 59 stuff(TMat23[float64])
61 stuff(TMat32[float64]) 60 stuff(TMat32[float64])
62 stuff(TMat33[float64]) 61 stuff(TMat3[float64])
63 stuff(TMat34[float64]) 62 stuff(TMat34[float64])
64 stuff(TMat43[float64]) 63 stuff(TMat43[float64])
65 stuff(TMat44[float64]) 64 stuff(TMat4[float64])
66 65
67 template withAllMats(stuff: untyped) = 66 template withAllMats(stuff: untyped) =
68 stuff(TMat22[int]) 67 stuff(TMat2[int])
69 stuff(TMat23[int]) 68 stuff(TMat23[int])
70 stuff(TMat32[int]) 69 stuff(TMat32[int])
71 stuff(TMat33[int]) 70 stuff(TMat3[int])
72 stuff(TMat34[int]) 71 stuff(TMat34[int])
73 stuff(TMat43[int]) 72 stuff(TMat43[int])
74 stuff(TMat44[int]) 73 stuff(TMat4[int])
75 stuff(TMat22[float]) 74 stuff(TMat2[float])
76 stuff(TMat23[float]) 75 stuff(TMat23[float])
77 stuff(TMat32[float]) 76 stuff(TMat32[float])
78 stuff(TMat33[float]) 77 stuff(TMat3[float])
79 stuff(TMat34[float]) 78 stuff(TMat34[float])
80 stuff(TMat43[float]) 79 stuff(TMat43[float])
81 stuff(TMat44[float]) 80 stuff(TMat4[float])
82 81
83 template testTranspose(t: typedesc) = 82 template testTranspose(t: typedesc) =
84 echo "testTranspose: ", t 83 echo "testTranspose: ", t
85 let m = t().randomized() 84 let m = t().randomized()
86 assert m == m.transposed().transposed() 85 assert m == m.transposed().transposed()
110 withAllMats(testTranspose) 109 withAllMats(testTranspose)
111 withAllIntegerMats(testAssignI) 110 withAllIntegerMats(testAssignI)
112 withAllFloatMats(testAssignF) 111 withAllFloatMats(testAssignF)
113 withAllMats(testRowCols) 112 withAllMats(testRowCols)
114 113
115 echo Unit22 114 echo Unit2
116 echo Unit22i 115 echo Unit2i
117 echo Unit22i8 116 echo Unit2i8
118 echo Unit22i16 117 echo Unit2i16
119 echo Unit22i32 118 echo Unit2i32
120 echo Unit22i64 119 echo Unit2i64
121 120
122 echo Unit33 121 echo Unit3
123 echo Unit33i 122 echo Unit3i
124 echo Unit33i8 123 echo Unit3i8
125 echo Unit33i16 124 echo Unit3i16
126 echo Unit33i32 125 echo Unit3i32
127 echo Unit33i64 126 echo Unit3i64
128 127
129 echo Unit44 128 echo Unit4
130 echo Unit44i 129 echo Unit4i
131 echo Unit44i8 130 echo Unit4i8
132 echo Unit44i16 131 echo Unit4i16
133 echo Unit44i32 132 echo Unit4i32
134 echo Unit44i64 133 echo Unit4i64
135 134
136 echo TMat22[float]().randomized() * One2.randomized() 135 echo TMat2[float32]().randomized() * One2.randomized()
137 echo TMat33[float]().randomized() * One3.randomized() 136 echo TMat3[float32]().randomized() * One3.randomized()
138 echo TMat44[float]().randomized() * One4.randomized() 137 echo TMat4[float32]().randomized() * One4.randomized()
139 138
140 randomize() 139 randomize()
141 testMatrix() 140 testMatrix()