-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.pas
536 lines (483 loc) · 19.4 KB
/
tests.pas
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
{$MODE OBJFPC} { -*- delphi -*- }
{$INCLUDE settings.inc}
program tests;
uses
{$IFDEF DEBUG} debug, {$ENDIF}
sysutils, storable, matcher, lists, physics, player, locations, things, grammarian, cuddlycamp, world, threshold,
testmechanics, testmechanics1, testmechanics2, testmechanics3, testmechanics4, testmechanics5, testmechanics6, testmechanics7, testmechanics8,
teststorage,
base64encoder, client; // client is used just to make sure it gets compiled when compiling tests
const
TestSaveFileName = '/tmp/tests.map.dat';
procedure TestBase64Encoder();
var
Failed: Boolean = False;
procedure CheckBase64(S1, S2: UTF8String);
begin
if (Base64(S1) <> S2) then
begin
Writeln('Base64: Encoding "', S1, '" gave "', Base64(S1), '" instead of "', S2, '".');
Failed := True;
end;
end;
begin
// Test Vectors from RFC 4648
CheckBase64('', '');
CheckBase64('f', 'Zg==');
CheckBase64('fo', 'Zm8=');
CheckBase64('foo', 'Zm9v');
CheckBase64('foob', 'Zm9vYg==');
CheckBase64('fooba', 'Zm9vYmE=');
CheckBase64('foobar', 'Zm9vYmFy');
if (Failed) then
Halt(1);
end;
procedure TestPlot();
var
TestWorld, TestWorld2: TWorld;
TestPlayer: TPlayer;
Proxy: TTestProxy;
Failed: Boolean;
OldF: File;
begin
Writeln('PLOT');
Proxy := TTestProxy.Create();
Proxy.Test('InitEden()');
TestWorld := InitEden();
Failed := False;
try
try
TestPlayer := TPlayer.Create('Tester', '', pIt);
TestPlayer.Adopt(@Proxy.HandleAvatarMessage, @Proxy.HandleForceDisconnect);
TestWorld.AddPlayer(TestPlayer);
TestPlayer.AnnounceAppearance();
{ Starting room test }
Proxy.Test('Starting location');
Proxy.ExpectString('Cave');
Proxy.SkipEverything();
TestWorld.Perform('look', TestPlayer);
Proxy.StopSkipping();
Proxy.ExpectString('Tunnel Trail');
Proxy.SkipEverything();
TestWorld.Perform('east', TestPlayer);
Proxy.StopSkipping();
Proxy.ExpectString('(the embroidered bag of holding labeled Tester)');
Proxy.ExpectString('You already have that.');
TestWorld.Perform('take all, and bag', TestPlayer);
{ test round-tripping }
Proxy.Test('Round-tripping');
StoreObjectToFile(TestSaveFileName, TestWorld, kSaveDataVersion);
TestWorld2 := ReadObjectFromFile(TestSaveFileName) as TWorld;
TestWorld2.Free();
Assign(OldF, TestSaveFileName);
{$I-} Erase(OldF); {$I+}
Proxy.Test('End');
except
on E: ETestError do
begin
Writeln(E.Message);
DumpExceptionBackTrace(Output);
Proxy.Clear();
Failed := True;
end;
on E: Exception do
begin
Writeln(E.Message);
DumpExceptionBackTrace(Output);
raise;
end;
end;
Proxy.ExpectDone();
Proxy.ExpectDisconnect(True);
finally
EmptyDisposalQueue();
TestWorld.Free();
Proxy.Free();
end;
if (Failed) then
begin
Writeln('FAILURE DETECTED');
Halt(1);
end;
end;
procedure TestMatcher();
var
TestID: Cardinal;
Failed: Boolean;
procedure RunMatcherTest(TestMatcher: TMatcher; Candidate: TTokens; Start: Cardinal; Pass: Cardinal; Flags: TMatcherFlags = 0);
var
Result: Cardinal;
begin
Inc(TestID);
Result := TestMatcher.Matches(Candidate, Start, Flags);
if (Result <> Pass) then
begin
Writeln('FAILED matcher test ', TestID, '; expected to match ', Pass, ' tokens but matched ', Result);
Failed := True;
end;
end;
procedure RunCanonicalMatchTest(TestMatcher: TMatcher; Pass: UTF8String; Flags: TMatcherFlags = 0);
var
Result: UTF8String;
begin
Inc(TestID);
Result := TestMatcher.GetCanonicalMatch(' ', Flags);
if (Result <> Pass) then
begin
Writeln('FAILED matcher test ', TestID, '; expected to find longest match "', Pass, '" but got "', Result, '"');
Failed := True;
end;
end;
var
TestMatcher, OtherMatcher: TMatcher;
Strings: TTokens;
begin
Writeln('PATTERN COMPILER');
Failed := False;
SetLength(Strings, 4); // $DFA- for Strings
Strings[0] := 'the';
Strings[1] := 'green';
Strings[2] := 'lantern';
Strings[3] := 'glowing';
TestID := 0;
CompilePattern('the', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the');
RunMatcherTest(TestMatcher, Strings, 0, 1);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(the) green', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the green');
RunMatcherTest(TestMatcher, Strings, 0, 2);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(((the green lantern glowing)))', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the green lantern glowing');
RunMatcherTest(TestMatcher, Strings, 0, 4);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('the? (green lantern)? glowing', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the green lantern glowing');
RunMatcherTest(TestMatcher, Strings, 0, 4);
RunMatcherTest(TestMatcher, Strings, 1, 3);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 1); // 20
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('the? ((glowing green)# lantern)&', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing green lantern');
RunMatcherTest(TestMatcher, Strings, 0, 3);
RunMatcherTest(TestMatcher, Strings, 1, 2);
RunMatcherTest(TestMatcher, Strings, 2, 1);
RunMatcherTest(TestMatcher, Strings, 3, 1); // 25
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(glowing lantern)@', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'glowing');
RunMatcherTest(TestMatcher, Strings, 0, 0);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 1);
RunMatcherTest(TestMatcher, Strings, 3, 1);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(the glowing lantern)*', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 1);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 2);
RunMatcherTest(TestMatcher, Strings, 3, 1);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(the glowing lantern)#', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 1);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 2);
RunMatcherTest(TestMatcher, Strings, 3, 1);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(the glowing lantern)%', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 1);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 1);
RunMatcherTest(TestMatcher, Strings, 3, 1);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('(the glowing lantern)&', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 1);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 1);
RunMatcherTest(TestMatcher, Strings, 3, 1);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('the+ glowing? lantern+', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 0);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('the/fail FAIL?/fail green lantern/fail (FAIL FAIL)?/glowing', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the FAIL green lantern FAIL FAIL');
RunMatcherTest(TestMatcher, Strings, 0, 3);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
RunCanonicalMatchTest(OtherMatcher, 'fail fail green fail glowing');
RunMatcherTest(OtherMatcher, Strings, 0, 0);
RunMatcherTest(OtherMatcher, Strings, 1, 0);
RunMatcherTest(OtherMatcher, Strings, 2, 0);
RunMatcherTest(OtherMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('the (glowing)?/(yellow green blue red)& lantern/(glowing lantern)*', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'the glowing lantern');
RunMatcherTest(TestMatcher, Strings, 0, 0);
RunMatcherTest(TestMatcher, Strings, 1, 0);
RunMatcherTest(TestMatcher, Strings, 2, 0);
RunMatcherTest(TestMatcher, Strings, 3, 0);
RunCanonicalMatchTest(OtherMatcher, 'the yellow green blue red glowing lantern');
RunMatcherTest(OtherMatcher, Strings, 0, 4);
RunMatcherTest(OtherMatcher, Strings, 1, 0);
RunMatcherTest(OtherMatcher, Strings, 2, 0);
RunMatcherTest(OtherMatcher, Strings, 3, 0);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('((((navy blue)& (wooden wood)@)# ((archway/archways arch/arches)@ (to the (north n)@)?))& (((navy blue)& (wooden wood)@ (north northern n)@)# (archway/archways arch/arches)@)&)@', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'navy blue wooden archway to the north');
RunCanonicalMatchTest(OtherMatcher, 'navy blue wooden archways to the north');
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('test (foo bar)@?', TestMatcher, OtherMatcher);
RunMatcherTest(TestMatcher, ['test'], 0, 1);
RunMatcherTest(TestMatcher, ['foo', 'bar'], 0, 0);
RunMatcherTest(TestMatcher, ['test', 'foo', 'bar'], 0, 2);
RunMatcherTest(TestMatcher, ['test', 'bar', 'foo'], 0, 2);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('test (foo bar)@? baz', TestMatcher, OtherMatcher);
RunMatcherTest(TestMatcher, ['test', 'baz'], 0, 2);
RunMatcherTest(TestMatcher, ['foo', 'bar', 'baz'], 0, 0);
RunMatcherTest(TestMatcher, ['test', 'foo', 'bar', 'baz'], 0, 0);
RunMatcherTest(TestMatcher, ['test', 'bar', 'foo', 'baz'], 0, 0);
RunMatcherTest(TestMatcher, ['test', 'foo', 'baz'], 0, 3);
RunMatcherTest(TestMatcher, ['test', 'bar', 'baz'], 0, 3);
TestMatcher.Free();
OtherMatcher.Free();
CompilePattern('((test a d) (test b) test (test a c))@', TestMatcher, OtherMatcher);
RunMatcherTest(TestMatcher, ['test'], 0, 1); // test 88
RunMatcherTest(TestMatcher, ['test', 'a'], 0, 1);
RunMatcherTest(TestMatcher, ['test', 'a', 'c'], 0, 3);
RunMatcherTest(TestMatcher, ['test', 'a', 'd'], 0, 3);
RunMatcherTest(TestMatcher, ['test', 'b'], 0, 2);
RunMatcherTest(TestMatcher, ['test', 'c'], 0, 1);
RunMatcherTest(TestMatcher, ['test', 'd'], 0, 1);
RunMatcherTest(TestMatcher, ['test', 'e'], 0, 1);
RunMatcherTest(TestMatcher, ['a'], 0, 0);
RunMatcherTest(TestMatcher, ['b'], 0, 0);
RunMatcherTest(TestMatcher, ['c'], 0, 0);
RunMatcherTest(TestMatcher, ['d'], 0, 0);
RunMatcherTest(TestMatcher, ['e'], 0, 0);
TestMatcher.Free();
OtherMatcher.Free();
SetLength(Strings, 3);
Strings[0] := 'burning';
Strings[1] := 'container';
Strings[2] := 'open';
CompilePattern('(burning:0 open:1 container/containers:2)#', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'burning container', 5); // flags 0 and 2 set
RunMatcherTest(TestMatcher, Strings, 0, 2, 5); // flags 0 and 2 set
RunMatcherTest(TestMatcher, Strings, 1, 1, 5); // flags 0 and 2 set
RunMatcherTest(TestMatcher, Strings, 2, 0, 5); // flags 0 and 2 set
RunMatcherTest(TestMatcher, Strings, 0, 0, 6); // flags 1 and 2 set
RunMatcherTest(TestMatcher, Strings, 1, 2, 6); // flags 1 and 2 set
RunMatcherTest(TestMatcher, Strings, 2, 1, 6); // flags 1 and 2 set
RunCanonicalMatchTest(OtherMatcher, 'burning containers', 5); // flags 0 and 2 set
RunMatcherTest(OtherMatcher, Strings, 0, 1, 5); // flags 0 and 2 set
RunMatcherTest(OtherMatcher, Strings, 1, 0, 5); // flags 0 and 2 set
RunMatcherTest(OtherMatcher, Strings, 2, 0, 5); // flags 0 and 2 set
RunMatcherTest(OtherMatcher, Strings, 0, 0, 6); // flags 1 and 2 set
RunMatcherTest(OtherMatcher, Strings, 1, 0, 6); // flags 1 and 2 set
RunMatcherTest(OtherMatcher, Strings, 2, 1, 6); // flags 1 and 2 set
TestMatcher.Free();
OtherMatcher.Free();
SetLength(Strings, 1);
Strings[0] := 'side';
CompilePattern('varnished? front?:1 side/sides', TestMatcher, OtherMatcher);
RunCanonicalMatchTest(TestMatcher, 'varnished side', 0);
RunMatcherTest(TestMatcher, Strings, 0, 1, 0);
TestMatcher.Free();
OtherMatcher.Free();
if (Failed) then Halt(1);
end;
type
TMolecule = class(TSpade)
end;
type
TMoleculeList = specialize TStorableList<TMolecule>;
procedure TestLists();
var
List1, List2: TMoleculeList;
Mol1, Mol2, Mol3: TMolecule;
Enum1, Enum2: TMoleculeList.TEnumerator;
Failed: Boolean;
TestCount: Cardinal;
procedure Check(Success: Boolean; S: UTF8String);
begin
Inc(TestCount);
if (not Success) then
begin
Writeln('Test #', TestCount, ': ', S);
Failed := True;
end;
end;
begin
RegisterStorableClass(TMoleculeList);
RegisterStorableClass(TMolecule);
Writeln('LISTS');
Failed := False;
TestCount := 0;
Mol1 := TMolecule.Create();
Mol2 := TMolecule.Create();
Mol3 := TMolecule.Create();
List1 := TMoleculeList.Create([slOwner]);
List1.AppendItem(Mol1);
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol1, 'Test failed');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
List2 := TMoleculeList.Create([slOwner]);
Enum1 := List2.GetEnumerator();
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol1, 'Test failed');
List2.AdoptItem(Enum1);
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
Enum1 := List1.GetEnumerator();
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
Enum1 := List2.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol1, 'Test failed');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
List1.AppendItem(Mol2);
List2.AdoptList(List1);
Enum1 := List1.GetEnumerator();
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
Enum1 := List2.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol1, 'Test failed');
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol2, 'Test failed');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
List2.AppendItem(Mol3);
Enum1 := List2.GetEnumerator(tdForward);
Check(Enum1.MoveNext(), 'Test after adding Mol3 failed');
Check(Enum1.Current = Mol1, 'Test after adding Mol3 failed');
Check(Enum1.MoveNext(), 'Test after adding Mol3 failed');
Check(Enum1.Current = Mol2, 'Test after adding Mol3 failed');
Check(Enum1.MoveNext(), 'Test after adding Mol3 failed');
Check(Enum1.Current = Mol3, 'Test after adding Mol3 failed');
Check(not Enum1.MoveNext(), 'Test after adding Mol3 failed');
Enum1.Free();
Enum1 := List2.GetEnumerator(tdForward);
Check(Enum1.MoveNext(), 'Test for adopting Mol2 from the middle failed');
Check(Enum1.Current = Mol1, 'Test for adopting Mol2 from the middle failed');
Check(Enum1.MoveNext(), 'Test for adopting Mol2 from the middle failed');
Check(Enum1.Current = Mol2, 'Test for adopting Mol2 from the middle failed');
List1.AdoptItem(Enum1);
Check(Enum1.MoveNext(), 'Test for adopting Mol2 from the middle failed');
Check(Enum1.Current = Mol3, 'Test for adopting Mol2 from the middle failed');
Check(not Enum1.MoveNext(), 'Test for adopting Mol2 from the middle failed');
Enum1.Free();
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'Test checking Mol2 got adopted failed');
Check(Enum1.Current = Mol2, 'Test checking Mol2 got adopted failed');
Check(not Enum1.MoveNext(), 'Test checking Mol2 got adopted failed');
Enum1.Free();
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'List adoption test failed - setup');
Check(Enum1.Current = Mol2, 'List adoption test failed - setup');
Enum2 := List2.GetEnumerator();
Check(Enum2.MoveNext(), 'List adoption test failed - setup');
Check(Enum2.Current = Mol1, 'List adoption test failed - setup');
Enum1.Free(); { can't have any live enumerators during adoption }
List2.AdoptList(List1);
Check(Enum2.MoveNext(), 'List adoption test failed - post adoption, pre traversal');
Check(Enum2.Current = Mol3, 'List adoption test failed - post adoption, pre traversal: Mol3 missing');
Check(Enum2.MoveNext(), 'List adoption test failed - post adoption, failed to traverse');
Check(Enum2.Current = Mol2, 'List adoption test failed - post adoption: Mol2 missing');
List1.AdoptItem(Enum2);
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol2, 'Test failed');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
Check(not Enum2.MoveNext(), 'Test failed');
Enum2.Free();
Enum2 := List2.GetEnumerator();
Check(Enum2.MoveNext(), 'Test failed');
Check(Enum2.Current = Mol1, 'Test failed');
List1.AdoptItem(Enum2);
Enum2.Free();
Enum1 := List1.GetEnumerator();
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol2, 'Test failed');
Check(Enum1.MoveNext(), 'Test failed');
Check(Enum1.Current = Mol1, 'Test failed');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
List2.AdoptList(List1);
Enum1 := List2.GetEnumerator(tdReverse);
Check(Enum1.MoveNext(), 'Reverse test failed - List2 empty');
Check(Enum1.Current = Mol1, 'Reverse test failed - Mol1 not at end');
Check(Enum1.MoveNext(), 'Reverse test failed');
Check(Enum1.Current = Mol2, 'Reverse test failed - Mol2 not in middle');
Check(Enum1.MoveNext(), 'Reverse test failed');
Check(Enum1.Current = Mol3, 'Reverse test failed - Mol3 not at start');
Check(not Enum1.MoveNext(), 'Test failed');
Enum1.Free();
{ molecules get freed by lists }
List1.Free();
List2.Free();
if (Failed) then Halt(1);
end;
begin
Writeln('CuddlyWorld Tests initializing...');
RegisterStorableClass(TTestWorld);
{$IFDEF DEBUG} Writeln('CuddlyWorld debugging enabled.'); {$ENDIF}
TestMechanics8.TestMechanics8();
TestMechanics7.TestMechanics7();
TestMechanics6.TestMechanics6();
TestMechanics5.TestMechanics5();
TestMechanics4.TestMechanics4();
TestMechanics3.TestMechanics3();
TestMechanics2.TestMechanics2();
TestMechanics1.TestMechanics1();
TestPlot();
Writeln('OTHERS');
TestClient();
TestStorage.RunTests();
TestBase64Encoder();
TestMatcher();
TestLists();
Writeln('CuddlyWorld Tests complete.');
end.