-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
399 lines (359 loc) · 15.9 KB
/
runtests.py
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import unittest
from unittest import case
import inspect
import numpy
from typeguard import typechecked, install_import_hook
from pathlib import Path
typechecks = True
if typechecks:
install_import_hook('MapLibs')
from MapLibs.t3d import *
from MapLibs.actor import *
class MockFile:
def __init__(self, content:str):
self.pos = 0
self.totallen = len(content)
self.lines = content.split('\n')
self.sep = ''
def readline(self) -> str:
s = self.lines[self.pos]
self.pos += 1
#print(inspect.stack()[1][3], 'readline:', s)
return s + self.sep
def reset(self):
print(inspect.stack()[1][3], 'MockFile.reset()', self.totallen, len(self.lines))
self.pos = 0
self.sep = ''
@typechecked
class T3DTestCase(unittest.TestCase):
def test_mirror(self):
orig = [12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] # verticies are counter-clockwise, right?
desired = [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
result = MirrorList(orig)
self.assertListEqual(result, desired, 'mirror')
def test_FormatCoord(self):
s = FormatPolyCoord(1)
self.assertEqual(s, '+00001.000000')
s = FormatPolyCoord(-1)
self.assertEqual(s, '-00001.000000')
s = FormatPolyCoord(0.1)
self.assertEqual(s, '+00000.100000')
s = FormatPolyCoord(-0.1)
self.assertEqual(s, '-00000.100000')
def assertRotatorsAlmostEqual(self, r, r2):
print(r,'vs',r2)
self.assertTrue( abs(r[0]-r2[0]) <3, 'assertRotatorsAlmostEqual pitch ' +str(r[0])+' vs '+str(r2[0]) )
self.assertTrue( abs(r[1]-r2[1]) <3, 'assertRotatorsAlmostEqual yaw ' +str(r[1])+' vs '+str(r2[1]) )
self.assertTrue( abs(r[2]-r2[2]) <3, 'assertRotatorsAlmostEqual roll ' +str(r[2])+' vs '+str(r2[2]) )
def test_rotation_matrix(self):
RADIANS_TO_UU = 65535 / np.pi / 2
self.assertAlmostEqual(65535 / RADIANS_TO_UU, 6.28319, 5, 'RADIANS_TO_UU')
self.assertNotAlmostEqual(65536 / RADIANS_TO_UU, 6.28319, 5, 'RADIANS_TO_UU')
iden_rot_mat = np.array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
rot = rotation_matrix(0,0,0)
numpy.testing.assert_array_almost_equal(rot, iden_rot_mat, 4, 'identity rot matrix')
rot = rotation_matrix(65535,65535,65535)
numpy.testing.assert_array_almost_equal(rot, iden_rot_mat, 4, 'identity rot matrix')
rot = rotation_matrix(-65535,-65535,-65535)
numpy.testing.assert_array_almost_equal(rot, iden_rot_mat, 4, 'identity rot matrix')
rot = (0,0,0)
coords = rotate_mult_coords((1,0,0), rot, rot, (1,1,1))
numpy.testing.assert_array_almost_equal(coords, (1,0,0), 4, 'rotated mult coords')
rot = (12454,42643,6953)
coords = rotate_mult_coords((1,0,0), rot, rot, (1,1,1))
numpy.testing.assert_array_almost_equal(coords, (1,0,0), 2, 'rotated mult coords')
rot = (0,0,0)
coords = rotate_mult_coords((1,2,3), rot, rot, (-1,1,1))
numpy.testing.assert_array_almost_equal(coords, (-1,2,3), 4, 'rotated mult coords')
rot = (0,16384,0)
coords = rotate_mult_coords((1,2,3), rot, rot, (-1,1,1))
numpy.testing.assert_array_almost_equal(coords, (1,-2,3), 4, 'rotated mult coords')
def test_rotators(self):
# people talking in bar
print('try to fix the people in the bar')
man_yaw = -43264 # 22271 in positive terms, but this is what the map file says
man_positive_yaw = 22271
man_desired_yaw = 10496
woman_yaw = -71024 # -5489 normalized, or 60046 in positive, but this is what the map file says
woman_desired_yaw = 38256 # or -27279
pinball_yaw = -32872
pinball_desired_yaw = 32872 # or -32663
rot_offset = 16384
rm = mirror_rotation((0, man_yaw, 0), rot_offset)
self.assertRotatorsAlmostEqual(rm, (0, man_desired_yaw, 0))
rm = mirror_rotation((0, man_positive_yaw, 0), rot_offset)
self.assertRotatorsAlmostEqual(rm, (0, man_desired_yaw, 0))
rm = mirror_rotation((0, woman_yaw, 0), rot_offset)
self.assertRotatorsAlmostEqual(rm, (0, woman_desired_yaw, 0))
rot_offset = classes_rot_offsets['Pinball']
rm = mirror_rotation((0, pinball_yaw, 0), rot_offset)
self.assertRotatorsAlmostEqual(rm, (0, pinball_desired_yaw, 0))
def test_read_polygon(self):
polygonfile.reset()
actor:Brush = CreateActor(None, 'Begin Actor Class=Brush Name=Test1')
self.assertEqual(actor.classname, 'Brush')
actor.ReadPolygon(polygonfile.readline(), polygonfile, None)
self.assertEqual(actor.lines[0], 'Begin Actor Class=Brush Name=Test1')
self.assertEqual(actor.lines[1], ' Begin Polygon Item=OUTSIDE Texture=ClenMedmWalnt_A Flags=32 Link=1')
self.assertEqual(actor.lines[-1], ' End Polygon')
self.assertEqual(polygonfile.readline(), 'End Test')
def test_read_brush(self):
print('test ReadBrush first')
brushfile.reset()
actor:Brush = CreateActor(None, brushfile.readline())
self.assertEqual(actor.classname, 'Brush')
ret = actor.ReadBrush(brushfile.readline(), brushfile, None)
self.assertEqual(actor.lines[0], 'Begin Actor Class=Brush Name=Brush49')
self.assertEqual(actor.lines[1], ' Begin Brush Name=Model14')
self.assertEqual(actor.lines[-1], ' End PolyList')
self.assertEqual(ret, ' End Brush')
self.assertEqual(brushfile.readline(), ' Brush=Model\'MyLevel.Model14\'')
self.assertTrue(isinstance(actor, Brush))
self.assertFalse(isinstance(actor, Mover))
print('now test Actor::Read')
brushfile.reset()
actor:Brush = CreateActor(None, brushfile.readline())
self.assertEqual(actor.classname, 'Brush')
actor.Read(brushfile, None)
actor.Finalize(None)
self.assertEqual(actor.lines[0], 'Begin Actor Class=Brush Name=Brush49')
self.assertEqual(actor.lines[1], ' Begin Brush Name=Model14')
self.assertEqual(actor.lines[-1], 'End Actor')
self.assertEqual(brushfile.readline(), 'End Test')
try:
self.assertEqual(len(str(actor)), 824, 'string of actor length')
except Exception as e:
print('ERROR!')
print(str(actor))
print(e)
raise
def test_read_actor(self):
actorfile.reset()
self.assertEqual(actorfile.readline(), 'Begin Map')
actor = CreateActor(None, actorfile.readline())
self.assertEqual(actor.classname, 'Jock')
self.assertFalse(isinstance(actor, Brush))
actor.Read(actorfile, None)
actor.Finalize(None)
self.assertEqual(actorfile.readline(), 'Begin Actor Class=AmbientSound Name=AmbientSound0')
def test_read_map(self):
actorfile.reset()
map = Map()
map.SetMirror((-1,1,1))
map._Read(actorfile)
self.assertEqual(len(map.actors), 2)
actorfile.reset()
actorfile.sep = '\r\n'# test with newlines
map = Map()
map.SetMirror((1,-1,1))
map._Read(actorfile)
self.assertEqual(len(map.actors), 2)
def test_map_file_mirror_x(self):
m = Map()
out = GetDefaultOut()
root = out.parent
f = root / 'tests' / 'RotationTest.t3d'
m.SetMirror((-1,1,1))
m.Read(f)
f = out / 't_mirror_x.t3d'
m.Write(f)
def test_map_file_mirror_y(self):
m = Map()
out = GetDefaultOut()
root = out.parent
f = root / 'tests' / 'RotationTest.t3d'
m.SetMirror((1,-1,1))
m.Read(f)
f = out / 't_mirror_y.t3d'
m.Write(f)
def test_map_file_bigger(self):
m = Map()
out = GetDefaultOut()
root = out.parent
f = root / 'tests' / 'RotationTest.t3d'
m.SetMirror((1.5,1.5,1.5))
m.Read(f)
f = out / 't_bigger.t3d'
m.Write(f)
def test_map_file_smaller(self):
m = Map()
out = GetDefaultOut()
root = out.parent
f = root / 'tests' / 'RotationTest.t3d'
m.SetMirror((0.7,0.7,0.7))
m.Read(f)
f = out / 't_smaller.t3d'
m.Write(f)
def test_unatco_pit(self):
unatcopit.reset()
unatcopit.sep = '\r\n'# test with newlines
map = Map()
map.SetMirror((-1,1,1))
map._Read(unatcopit)
print(map.ToString())
### TEST DATA ###
polygonfile = MockFile(
""" Begin Polygon Item=OUTSIDE Texture=ClenMedmWalnt_A Flags=32 Link=1
Origin -00004.000000,+00068.000000,-00004.000000
Normal +00000.000000,+00000.000000,-00001.000000
TextureU -00000.000000,-00001.000000,-00000.000000
TextureV -00001.000000,+00000.000000,+00000.000000
Vertex -00004.000000,+00072.000000,-00004.000000
Vertex +00004.000000,+00072.000000,-00004.000000
Vertex +00004.000000,-00072.000000,-00004.000000
Vertex -00004.000000,-00072.000000,-00004.000000
End Polygon
End Test""")
brushfile = MockFile(
"""Begin Actor Class=Brush Name=Brush49
Begin Brush Name=Model14
Begin PolyList
Begin Polygon Item=OUTSIDE Texture=ClenMedmWalnt_A Flags=32 Link=0
Origin -00004.000000,-00068.000000,+00004.000000
Normal +00000.000000,+00000.000000,+00001.000000
TextureU +00000.000000,+00001.000000,+00000.000000
TextureV -00001.000000,+00000.000000,+00000.000000
Vertex -00004.000000,-00072.000000,+00004.000000
Vertex +00004.000000,-00072.000000,+00004.000000
Vertex +00004.000000,+00072.000000,+00004.000000
Vertex -00004.000000,+00072.000000,+00004.000000
End Polygon
End PolyList
End Brush
Brush=Model'MyLevel.Model14'
PrePivot=(X=4.000000,Y=68.000000,Z=-4.000000)
Name=Brush49
End Actor
End Test""")
actorfile = MockFile(
"""Begin Map
Begin Actor Class=Jock Name=Jock0
Orders=Standing
bLikesNeutral=False
bHateCarcass=True
bHateDistress=True
bReactAlarm=False
bReactShot=True
bReactDistress=True
InitialAlliances(0)=(AllianceName=Player)
InitialAlliances(1)=(AllianceName=BarFlys)
InitialInventory(0)=(Inventory=Class'DeusEx.WeaponStealthPistol')
InitialInventory(1)=(Inventory=Class'DeusEx.Ammo10mm',Count=12)
InitialInventory(2)=(Inventory=Class'DeusEx.WeaponCombatKnife')
FootRegion=(Zone=ZoneInfo'MyLevel.ZoneInfo5',iLeaf=492,ZoneNumber=1)
HeadRegion=(Zone=ZoneInfo'MyLevel.ZoneInfo5',iLeaf=485,ZoneNumber=1)
ViewRotation=(Yaw=11040)
VisibilityThreshold=0.000000
Alliance=BarFlys
LastRenderTime=139.187988
DistanceFromPlayer=542.363525
Level=LevelInfo'MyLevel.LevelInfo0'
Tag=Jock
Base=LevelInfo'MyLevel.LevelInfo0'
Region=(Zone=ZoneInfo'MyLevel.ZoneInfo5',iLeaf=485,ZoneNumber=1)
Location=(X=-942.777710,Y=-487.315552,Z=48.964230)
Rotation=(Yaw=11040)
OldLocation=(X=-866.068909,Y=1041.609253,Z=-16.400154)
BarkBindName="Man"
UnfamiliarName="Pilot guy"
Name=Jock0
End Actor
Begin Actor Class=AmbientSound Name=AmbientSound0
LastRenderTime=139.187988
DistanceFromPlayer=3083.201416
Level=LevelInfo'MyLevel.LevelInfo0'
Tag=AmbientSound
Region=(Zone=ZoneInfo'MyLevel.ZoneInfo5',iLeaf=78,ZoneNumber=1)
Location=(X=-3415.629883,Y=673.263794,Z=59.187805)
OldLocation=(X=-1396.085693,Y=1057.143433,Z=-53.899948)
SoundRadius=6
SoundVolume=100
AmbientSound=Sound'Ambient.Ambient.EchoWaterDrips'
Name=AmbientSound0
End Actor
End Map""")
unatcopit = MockFile(
"""Begin Map
Begin Actor Class=Brush Name=Brush359
CsgOper=CSG_Subtract
MainScale=(SheerAxis=SHEER_ZX)
PostScale=(Scale=(X=0.625000,Y=1.454545,Z=2.100000),SheerAxis=SHEER_ZX)
DistanceFromPlayer=907.171448
Level=LevelInfo'MyLevel.LevelInfo0'
Tag=Brush
Region=(Zone=LevelInfo'MyLevel.LevelInfo0',iLeaf=-1)
Location=(X=-272.000000,Y=576.000000,Z=240.000000)
Rotation=(Pitch=16384,Yaw=16384)
Begin Brush Name=Model354
Begin PolyList
Begin Polygon Item=OUTSIDE Texture=Uob_Far_Wall_B Flags=8388608 Link=0
Origin -00194.285721,-00128.000000,+00088.000023
Normal +00000.000000,+00000.000000,+00001.000000
TextureU +00000.000000,+00001.250000,+00000.000000
TextureV -00004.200000,+00000.000000,+00000.000000
Vertex -00080.000000,-00128.000000,+00088.000000
Vertex +00080.000000,-00128.000000,+00088.000000
Vertex +00080.000000,+00128.000000,+00088.000000
Vertex -00080.000000,+00128.000000,+00088.000000
End Polygon
Begin Polygon Item=OUTSIDE Texture=Uob_Far_Wall_B Flags=8388608 Link=1
Origin -00194.285721,+00128.000000,-00088.000023
Normal +00000.000000,+00000.000000,-00001.000000
TextureU +00000.000000,-00001.249999,+00000.000000
TextureV -00004.200000,+00000.000000,+00000.000000
Vertex -00080.000000,+00128.000000,-00088.000000
Vertex +00080.000000,+00128.000000,-00088.000000
Vertex +00080.000000,-00128.000000,-00088.000000
Vertex -00080.000000,-00128.000000,-00088.000000
End Polygon
Begin Polygon Item=OUTSIDE Texture=Marker_sky Link=2
Origin -00080.000000,+00128.000000,-00088.000000
Normal +00000.000000,+00001.000000,+00000.000000
TextureU +00001.000000,+00000.000000,+00000.000000
TextureV +00000.000000,+00000.000000,-00001.000000
Vertex -00080.000000,+00128.000000,-00088.000000
Vertex -00080.000000,+00128.000000,+00088.000000
Vertex +00080.000000,+00128.000000,+00088.000000
Vertex +00080.000000,+00128.000000,-00088.000000
End Polygon
Begin Polygon Item=OUTSIDE Texture=Uob_Far_Wall_B Flags=8388608 Link=3
Origin -00194.285721,-00128.000000,-00088.000023
Normal +00000.000000,-00001.000000,+00000.000000
TextureU +00000.000000,+00000.000000,+00002.909090
TextureV -00004.200000,+00000.000000,+00000.000000
Vertex +00080.000000,-00128.000000,-00088.000000
Vertex +00080.000000,-00128.000000,+00088.000000
Vertex -00080.000000,-00128.000000,+00088.000000
Vertex -00080.000000,-00128.000000,-00088.000000
End Polygon
Begin Polygon Item=OUTSIDE Texture=UN_Wall_Green Flags=8388608 Link=4
Origin +00080.000015,-00307.199921,+00308.000122
Normal +00001.000000,+00000.000000,+00000.000000
TextureU +00000.000000,-00000.625000,+00000.000000
TextureV +00000.000000,+00000.000000,-00001.454545
Vertex +00080.000000,+00128.000000,-00088.000000
Vertex +00080.000000,+00128.000000,+00088.000000
Vertex +00080.000000,-00128.000000,+00088.000000
Vertex +00080.000000,-00128.000000,-00088.000000
End Polygon
Begin Polygon Item=OUTSIDE Texture=Marker_sky Link=5
Origin -00080.000000,-00128.000000,-00088.000000
Normal -00001.000000,+00000.000000,+00000.000000
TextureU +00000.000000,+00001.000000,+00000.000000
TextureV +00000.000000,+00000.000000,-00001.000000
Vertex -00080.000000,-00128.000000,-00088.000000
Vertex -00080.000000,-00128.000000,+00088.000000
Vertex -00080.000000,+00128.000000,+00088.000000
Vertex -00080.000000,+00128.000000,-00088.000000
End Polygon
End PolyList
End Brush
Brush=Model'MyLevel.Model354'
PrePivot=(X=-80.000000,Y=128.000000,Z=-88.000023)
Name=Brush359
End Actor
End Map""")
if __name__ == "__main__":
unittest.main(verbosity=9, warnings="error", failfast=True)