-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.ml
396 lines (394 loc) · 20.6 KB
/
unit_test.ml
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
open General.Abbr
open Tst
open Collide
module T = struct
let test = "Collide" >:: [
Ring.Test.test;
"Simulation" >:: Simulation.(
let make name max_date initial_balls expected_events expected_balls =
name >: (lazy (
let initial_simulation = create ~dimensions:(400., 300.) initial_balls in
let (actual_events, final_simulation) = advance ~date:max_date initial_simulation in
check_float ~expected:max_date (date final_simulation);
check_list_poly ~repr:Ball.repr ~expected:expected_balls (balls final_simulation);
let repr (date, event) =
Frmt.apply "(%f, %s)" date (Event.repr event) (*BISECT-IGNORE*)
in
check_list_poly ~repr ~expected:expected_events actual_events
))
in
[
"Single-ball" >:: (
let make name max_date initial_ball expected_events expected_ball =
make name max_date [initial_ball] expected_events [expected_ball]
in
[
make "advance" 2.
{Ball.radius=10.; density=1.; position=(40., 60.); velocity=(1., 2.)}
[]
{Ball.radius=10.; density=1.; position=(42., 64.); velocity=(1., 2.)};
make "start from left" 1.
{Ball.radius=10.; density=1.; position=(10., 150.); velocity=(1., 0.)}
[]
{Ball.radius=10.; density=1.; position=(11., 150.); velocity=(1., 0.)};
make "start from top" 1.
{Ball.radius=10.; density=1.; position=(200., 10.); velocity=(0., 1.)}
[]
{Ball.radius=10.; density=1.; position=(200., 11.); velocity=(0., 1.)};
make "start from right" 1.
{Ball.radius=10.; density=1.; position=(390., 150.); velocity=(-1., 0.)}
[]
{Ball.radius=10.; density=1.; position=(389., 150.); velocity=(-1., 0.)};
make "start from bottom" 1.
{Ball.radius=10.; density=1.; position=(200., 290.); velocity=(0., -1.)}
[]
{Ball.radius=10.; density=1.; position=(200., 289.); velocity=(0., -1.)};
make "start to left" 1.
{Ball.radius=10.; density=1.; position=(10., 150.); velocity=(-1., 0.)}
[
(0., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 150.); velocity=(-1., 0.)};
after={radius=10.; density=1.; position=(10., 150.); velocity=(1., 0.)};
});
]
{Ball.radius=10.; density=1.; position=(11., 150.); velocity=(1., 0.)};
make "start to top" 1.
{Ball.radius=10.; density=1.; position=(200., 10.); velocity=(0., -1.)}
[
(0., WallBallCollision {
wall=Top;
before={radius=10.; density=1.; position=(200., 10.); velocity=(0., -1.)};
after={radius=10.; density=1.; position=(200., 10.); velocity=(0., 1.)};
});
]
{Ball.radius=10.; density=1.; position=(200., 11.); velocity=(0., 1.)};
make "start to right" 1.
{Ball.radius=10.; density=1.; position=(390., 150.); velocity=(1., 0.)}
[
(0., WallBallCollision {
wall=Right;
before={radius=10.; density=1.; position=(390., 150.); velocity=(1., 0.)};
after={radius=10.; density=1.; position=(390., 150.); velocity=(-1., 0.)};
});
]
{Ball.radius=10.; density=1.; position=(389., 150.); velocity=(-1., 0.)};
make "start to bottom" 1.
{Ball.radius=10.; density=1.; position=(200., 290.); velocity=(0., 1.)}
[
(0., WallBallCollision {
wall=Bottom;
before={radius=10.; density=1.; position=(200., 290.); velocity=(0., 1.)};
after={radius=10.; density=1.; position=(200., 290.); velocity=(0., -1.)};
});
]
{Ball.radius=10.; density=1.; position=(200., 289.); velocity=(0., -1.)};
make "start to bottom-right" 2.
{Ball.radius=10.; density=1.; position=(389., 289.); velocity=(1., 1.)}
[
(1., WallBallCollision {
wall=Right;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(1., 1.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 1.)}
});
(1., WallBallCollision {
wall=Bottom;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 1.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., -1.)}
});
]
{Ball.radius=10.; density=1.; position=(389., 289.); velocity=(-1., -1.)};
make "start at bottom-right" 1.
{Ball.radius=10.; density=1.; position=(390., 290.); velocity=(1., 1.)}
[
(0., WallBallCollision {
wall=Right;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(1., 1.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 1.)}
});
(0., WallBallCollision {
wall=Bottom;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 1.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., -1.)}
});
]
{Ball.radius=10.; density=1.; position=(389., 289.); velocity=(-1., -1.)};
make "hit left wall" 2.
{Ball.radius=10.; density=1.; position=(11., 60.); velocity=(-1., 2.)}
[
(1., WallBallCollision {
wall=Left;
before={Ball.radius=10.; density=1.; position=(10., 62.); velocity=(-1., 2.)};
after={Ball.radius=10.; density=1.; position=(10., 62.); velocity=(1., 2.)}
});
]
{Ball.radius=10.; density=1.; position=(11., 64.); velocity=(1., 2.)};
make "hit right wall" 2.
{Ball.radius=10.; density=1.; position=(389., 60.); velocity=(1., 2.)}
[
(1., WallBallCollision {
wall=Right;
before={Ball.radius=10.; density=1.; position=(390., 62.); velocity=(1., 2.)};
after={Ball.radius=10.; density=1.; position=(390., 62.); velocity=(-1., 2.)}
});
]
{Ball.radius=10.; density=1.; position=(389., 64.); velocity=(-1., 2.)};
make "hit top wall" 2.
{Ball.radius=10.; density=1.; position=(100., 12.); velocity=(1., -2.)}
[
(1., WallBallCollision {
wall=Top;
before={Ball.radius=10.; density=1.; position=(101., 10.); velocity=(1., -2.)};
after={Ball.radius=10.; density=1.; position=(101., 10.); velocity=(1., 2.)}
});
]
{Ball.radius=10.; density=1.; position=(102., 12.); velocity=(1., 2.)};
make "hit bottom wall" 2.
{Ball.radius=10.; density=1.; position=(100., 288.); velocity=(1., 2.)}
[
(1., WallBallCollision {
wall=Bottom;
before={Ball.radius=10.; density=1.; position=(101., 290.); velocity=(1., 2.)};
after={Ball.radius=10.; density=1.; position=(101., 290.); velocity=(1., -2.)}
});
]
{Ball.radius=10.; density=1.; position=(102., 288.); velocity=(1., -2.)};
make "hit corner" 2.
{Ball.radius=10.; density=1.; position=(389., 288.); velocity=(1., 2.)}
[
(1., WallBallCollision {
wall=Right;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(1., 2.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 2.)}
});
(1., WallBallCollision {
wall=Bottom;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., 2.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-1., -2.)}
});
]
{Ball.radius=10.; density=1.; position=(389., 288.); velocity=(-1., -2.)};
make "hit wall after corner" 40.
{Ball.radius=10.; density=1.; position=(380., 288.); velocity=(10., 2.)}
[
(1., WallBallCollision {
wall=Right;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(10., 2.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-10., 2.)};
});
(1., WallBallCollision {
wall=Bottom;
before={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-10., 2.)};
after={Ball.radius=10.; density=1.; position=(390., 290.); velocity=(-10., -2.)};
});
(39., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 214.); velocity=(-10., -2.)};
after={radius=10.; density=1.; position=(10., 214.); velocity=(10., -2.)};
});
]
{Ball.radius=10.; density=1.; position=(20., 212.); velocity=(10., -2.)};
make "hit corners" 80.
{Ball.radius=10.; density=1.; position=(48., 38.); velocity=(38., 28.)}
[
(9., WallBallCollision {
wall=Right;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., 28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(-38., 28.)};
});
(9., WallBallCollision {
wall=Bottom;
before={radius=10.; density=1.; position=(390., 290.); velocity=(-38., 28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(-38., -28.)};
});
(19., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., -28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(38., -28.)};
});
(19., WallBallCollision {
wall=Top;
before={radius=10.; density=1.; position=(10., 10.); velocity=(38., -28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(38., 28.)};
});
(29., WallBallCollision {
wall=Bottom;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., 28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
});
(29., WallBallCollision {
wall=Right;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(-38., -28.)};
});
(39., WallBallCollision {
wall=Top;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., -28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
});
(39., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(38., 28.)};
});
(49., WallBallCollision {
wall=Bottom;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., 28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
});
(49., WallBallCollision {
wall=Right;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(-38., -28.)};
});
(59., WallBallCollision {
wall=Top;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., -28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
});
(59., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(38., 28.)};
});
(69., WallBallCollision {
wall=Bottom;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., 28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
});
(69., WallBallCollision {
wall=Right;
before={radius=10.; density=1.; position=(390., 290.); velocity=(38., -28.)};
after={radius=10.; density=1.; position=(390., 290.); velocity=(-38., -28.)};
});
(79., WallBallCollision {
wall=Top;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., -28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
});
(79., WallBallCollision {
wall=Left;
before={radius=10.; density=1.; position=(10., 10.); velocity=(-38., 28.)};
after={radius=10.; density=1.; position=(10., 10.); velocity=(38., 28.)};
});
]
{Ball.radius=10.; density=1.; position=(48., 38.); velocity=(38., 28.)};
]
);
"Dual-ball" >:: (
let make name max_date initial_ball_1 initial_ball_2 expected_events expected_ball_1 expected_ball_2 =
make name max_date [initial_ball_1; initial_ball_2] expected_events [expected_ball_1; expected_ball_2]
in
[
make "no collision of balls going in same direction" 2.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(1., 0.)}
[]
{Ball.radius=10.; density=1.; position=(42., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(63., 100.); velocity=(1., 0.)};
make "no collision of balls going in same direction" 2.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(2., 0.)}
[]
{Ball.radius=10.; density=1.; position=(42., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(65., 100.); velocity=(2., 0.)};
make "balls staying in contact" 2.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(60., 100.); velocity=(1., 0.)}
[]
{Ball.radius=10.; density=1.; position=(42., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(62., 100.); velocity=(1., 0.)};
make "frontal horizontal collision of identical balls" 2.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(0., 0.)}
[
(1., BallBallCollision {
before=(
{radius=10.; density=1.; position=(41., 100.); velocity=(1., 0.)},
{radius=10.; density=1.; position=(61., 100.); velocity=(0., 0.)}
);
after=(
{radius=10.; density=1.; position=(41., 100.); velocity=(0., 0.)},
{radius=10.; density=1.; position=(61., 100.); velocity=(1., 0.)}
);
});
]
{Ball.radius=10.; density=1.; position=(41., 100.); velocity=(0., 0.)}
{Ball.radius=10.; density=1.; position=(62., 100.); velocity=(1., 0.)};
make "frontal horizontal collision of identical balls" 2.
{Ball.radius=10.; density=1.; position=(39., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(-1., 0.)}
[
(1., BallBallCollision {
before=(
{radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)},
{radius=10.; density=1.; position=(60., 100.); velocity=(-1., 0.)}
);
after=(
{radius=10.; density=1.; position=(40., 100.); velocity=(-1., 0.)},
{radius=10.; density=1.; position=(60., 100.); velocity=(1., 0.)}
);
});
]
{Ball.radius=10.; density=1.; position=(39., 100.); velocity=(-1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(1., 0.)};
make "frontal horizontal collision of identical balls" 1.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=1.; position=(60., 100.); velocity=(-1., 0.)}
[
(0., BallBallCollision {
before=(
{radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)},
{radius=10.; density=1.; position=(60., 100.); velocity=(-1., 0.)}
);
after=(
{radius=10.; density=1.; position=(40., 100.); velocity=(-1., 0.)},
{radius=10.; density=1.; position=(60., 100.); velocity=(1., 0.)}
);
});
]
{Ball.radius=10.; density=1.; position=(39., 100.); velocity=(-1., 0.)}
{Ball.radius=10.; density=1.; position=(61., 100.); velocity=(1., 0.)};
make "frontal horizontal collision of different balls of same mass" 2.
{Ball.radius=10.; density=1.; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=100.; density=0.01; position=(151., 100.); velocity=(0., 0.)}
[
(1., BallBallCollision {
before=(
{radius=10.; density=1.; position=(41., 100.); velocity=(1., 0.)},
{radius=100.; density=0.01; position=(151., 100.); velocity=(0., 0.)}
);
after=(
{radius=10.; density=1.; position=(41., 100.); velocity=(0., 0.)},
{radius=100.; density=0.01; position=(151., 100.); velocity=(1., 0.)}
);
});
]
{Ball.radius=10.; density=1.; position=(41., 100.); velocity=(0., 0.)}
{Ball.radius=100.; density=0.01; position=(152., 100.); velocity=(1., 0.)};
make "frontal horizontal collision of different balls of different mass" 2.
{Ball.radius=10.; density=0.1; position=(40., 100.); velocity=(1., 0.)}
{Ball.radius=10.; density=0.9; position=(61., 100.); velocity=(0., 0.)}
[
(1., BallBallCollision {
before=(
{radius=10.; density=0.1; position=(41., 100.); velocity=(1., 0.)},
{radius=10.; density=0.9; position=(61., 100.); velocity=(0., 0.)}
);
after=(
{radius=10.; density=0.1; position=(41., 100.); velocity=(-0.80, 0.)},
{radius=10.; density=0.9; position=(61., 100.); velocity=(0.20, 0.)}
);
});
]
{Ball.radius=10.; density=0.1; position=(40.20, 100.); velocity=(-0.80, 0.)}
{Ball.radius=10.; density=0.9; position=(61.20, 100.); velocity=(0.20, 0.)};
]
);
]
);
]
end
let () =
let argv = Li.of_array OCamlStandard.Sys.argv in
Exit.exit (command_line_main ~argv T.test)