-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcVecUnitTests.tbasic
More file actions
259 lines (230 loc) · 5.76 KB
/
cVecUnitTests.tbasic
File metadata and controls
259 lines (230 loc) · 5.76 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
' cVec unit tests by kryton9 - Kent Sarikaya 2017
Uses "Console"
#INCLUDE "cVec.tbasicu"
' needs internet, but will use the latest version
' #INCLUDE "https://raw.githubusercontent.com/kryton9/thinBasic-cVec/master/cVec.tbasicu"
Type tTest
test As String
result As String
Function txt ( ) As String
String s = Me.test + $TAB + Me.result
Return s
End Function
End Type
Byte i 'used in for loops
Byte numTests = 21
Dim unitTests ( numTests ) As tTest
String methods ( numTests )
methods ( 1 ) = "cpy2", "cpyFrm", "eqls", "inc", "dec", "scl", "div", "dot", "dstnc", "cross",
"limit", "mag", "nrmlz", "rndmz", "hdng", "angle", "rot", "txt", "out", "setMag", "frmAngle"
For i = 1 To numTests
unitTests ( i ).test = methods ( i )
unitTests ( i ).result = "not developed or tested"
Next
' Test 1 : cpy2
Dim a As cVec 3, 4, 5
Dim b As cVec 1, 1, 1
a.cpy2 b
If b.x = 3 And b.y = 4 And b.z = 5 Then
unitTests ( 1 ).result = "Passed"
Else
unitTests ( 1 ).result = "Failed"
End If
' Test 2 : cpyFrm
a.x = 3 : a.y = 4 : a.z = 5
b.x = 1 : b.y = 1 : b.z = 1
a.cpyFrm b
If a.x = 1 And a.y = 1 And a.z = 1 Then
unitTests ( 2 ).result = "Passed"
Else
unitTests ( 2 ).result = "Failed"
End If
' Test 3 : eqls
a.eqls 3, 4, 5
If a.x = 3 And a.y = 4 And a.z = 5 Then
unitTests ( 3 ).result = "Passed"
Else
unitTests ( 3 ).result = "Failed"
End If
' Test 4 : inc
a.x = 3 : a.y = 4 : a.z = 5
b.x = 1 : b.y = 1 : b.z = 1
a.inc b
If a.x = 4 And a.y = 5 And a.z = 6 Then
unitTests ( 4 ).result = "Passed"
Else
unitTests ( 4 ).result = "Failed"
End If
' Test 5 : dec
a.x = 4 : a.y = 5 : a.z = 6
b.x = 1 : b.y = 1 : b.z = 1
a.dec b
If a.x = 3 And a.y = 4 And a.z = 5 Then
unitTests ( 5 ).result = "Passed"
Else
unitTests ( 5 ).result = "Failed"
End If
' Test 6 : scl
b.x = 1 : b.y = 1 : b.z = 1
b.scl 5
If b.x = 5 And b.y = 5 And b.z = 5 Then
unitTests ( 6 ).result = "Passed"
Else
unitTests ( 6 ).result = "Failed"
End If
' Test 7 : div
a.x = 9 : a.y = 12 : a.z = 15
a.div 3
If a.x = 3 And a.y = 4 And a.z = 5 Then
unitTests ( 7 ).result = "Passed"
Else
unitTests ( 7 ).result = "Failed"
End If
' Test 8 : dot
a.x = 3 : a.y = 4 : a.z = 5
b.x = 7 : b.y = 8 : b.z = 9
Single result = a.dot b
'PrintL result
If result = 98 Then
unitTests ( 8 ).result = "Passed"
Else
unitTests ( 8 ).result = "Failed"
End If
' Test 9 : dstnc
a.x = 3 : a.y = 4 : a.z = 5
b.x = 7 : b.y = 8 : b.z = 9
result = a.dstnc b
'PrintL result
If result > 6.928202 And result < 6.928204 Then
unitTests ( 9 ).result = "Passed"
Else
unitTests ( 9 ).result = "Failed"
End If
' Test 10 : cross
a.x = 3 : a.y = 4 : a.z = 5
b.x = 7 : b.y = 8 : b.z = 9
Dim c As cVec
a.cross b, c
If c.x = -4 And c.y = 8 And c.z = -4 Then
unitTests ( 10 ).result = "Passed"
Else
unitTests ( 10 ).result = "Failed"
End If
' Test 11 : limit
a.x = 10 : a.y = 20 : a.z = 30
a.limit 5.5
'a.out
If ( a.x > 1.469935 And a.x < 1.469937 ) And _
( a.y > 2.939875 And a.y < 2.939877 ) And _
( a.z > 4.409811 And a.z < 4.409813 ) Then
unitTests ( 11 ).result = "Passed"
Else
unitTests ( 11 ).result = "Failed"
End If
' Test 12 : mag
a.x = 3 : a.y = 4 : a.z = 5
result = a.mag
'PrintL result
If result > 7.071067 And result < 7.071069 Then
unitTests ( 12 ).result = "Passed"
Else
unitTests ( 12 ).result = "Failed"
End If
' Test 13 : nrmlz
a.x = 3 : a.y = 4 : a.z = 5
a.nrmlz
'a.out
If ( a.x > 0.424263 And a.x < 0.424265 ) And _
( a.y > 0.565684 And a.y < 0.565686 ) And _
( a.z > 0.707106 And a.z < 0.707108 ) Then
unitTests ( 13 ).result = "Passed"
Else
unitTests ( 13 ).result = "Failed"
End If
' Test 14 : rndmz
a.x = 9 : a.y = 12 : a.z = 15
a.rndmz
'a.out
If a.x <> 9 And a.y <> 12 And a.z <> 15 Then
unitTests ( 14 ).result = "Passed"
Else
unitTests ( 14 ).result = "Failed"
End If
' Test 15 : hdng
' works only on 2d vectors, to use with 3d pass 0 for z
Dim d As cVec 1, 3
result = d.hdng
'PrintL result
If result > 1.249044 And result <1.249046 Then
unitTests ( 15 ).result = "Passed"
Else
unitTests ( 15 ).result = "Failed"
End If
' Test 16 : angle
d.eqls 10, 20
Dim e As cVec 60, 80
result = d.angle e
'PrintL result
If result > 10.304845 And result < 10.304847 Then
unitTests ( 16 ).result = "Passed"
Else
unitTests ( 16 ).result = "Failed"
End If
' Test 17 : rot
' works only on 2d vectors, to use with 3d pass 0 for z
d.eqls 10, 20
d.rot (Pi / 2)
'd.out
If d.x = -20.0 And d.y = 9.999999 Then
unitTests ( 17 ).result = "Passed"
Else
unitTests ( 17 ).result = "Failed"
End If
' Test 18 : txt
a.x = 9 : a.y = 12 : a.z = 15
String s = ""
s = a.txt
If s <> "" Then
unitTests ( 18 ).result = "Passed"
Else
unitTests ( 18 ).result = "Failed"
End If
' Test 19 : out
a.x = 9 : a.y = 12 : a.z = 15
Print "test 19 out: "
Boolean ok = a.out
PrintL
If ok = TRUE Then
unitTests ( 19 ).result = "Passed"
Else
unitTests ( 19 ).result = "Failed"
End If
' Test 20 : setMag
a.eqls 3, 4, 0
a.setMag 10
If a.x = 6 And a.y = 8 And a.z = 0 Then
unitTests ( 20 ).result = "Passed"
Else
unitTests ( 20 ).result = "Failed"
End If
' Test 21 : frmAngle
a.frmAngle 45
If ( a.x > 0.525321 And a.x < 0.525323 ) And _
( a.y > 0.850903 And a.y < 0.850905 ) Then
unitTests ( 21 ).result = "Passed"
Else
unitTests ( 21 ).result = "Failed"
End If
Byte displayColor
For i = 1 To numTests
displayColor = %CCOLOR_FGRAY
If unitTests ( i ).result = "Passed" Then
displayColor = %CCOLOR_FLIGHTGREEN
ElseIf unitTests ( i ).result = "Failed" Then
displayColor = %CCOLOR_FLIGHTRED
EndIf
PrintL "test: " + i + " " + unitTests ( i ).txt In displayColor
Next
PrintL
PrintL "Press a key to end program"
WaitKey