| 1 | unit TestCases;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, TestCase, Engine;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 |
|
|---|
| 10 | { TTestCaseRun }
|
|---|
| 11 |
|
|---|
| 12 | TTestCaseRun = class(TTestCase)
|
|---|
| 13 | InitTrackCount: Integer;
|
|---|
| 14 | Engine: TEngine;
|
|---|
| 15 | procedure Run; override;
|
|---|
| 16 | constructor Create; override;
|
|---|
| 17 | destructor Destroy; override;
|
|---|
| 18 | end;
|
|---|
| 19 |
|
|---|
| 20 | function InitTestCases: TTestCases;
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 | implementation
|
|---|
| 24 |
|
|---|
| 25 | function InitTestCases: TTestCases;
|
|---|
| 26 | begin
|
|---|
| 27 | Result := TTestCases.Create;
|
|---|
| 28 | with Result do begin
|
|---|
| 29 | AddNew('Tick', TTestCaseRun);
|
|---|
| 30 | with TTestCaseRun(AddNew('One track', TTestCaseRun)) do begin
|
|---|
| 31 | InitTrackCount := 1;
|
|---|
| 32 | end;
|
|---|
| 33 | end;
|
|---|
| 34 | end;
|
|---|
| 35 |
|
|---|
| 36 | { TTestCaseRun }
|
|---|
| 37 |
|
|---|
| 38 | procedure TTestCaseRun.Run;
|
|---|
| 39 | var
|
|---|
| 40 | I: Integer;
|
|---|
| 41 | MetroLine: TMetroLine;
|
|---|
| 42 | UsedLines: Integer;
|
|---|
| 43 | begin
|
|---|
| 44 | Engine.Map.Size := Point(640, 480);
|
|---|
| 45 | Engine.View.DestRect := Rect(0, 0, 640, 480);
|
|---|
| 46 | Engine.NewGame;
|
|---|
| 47 | if InitTrackCount > 0 then begin
|
|---|
| 48 | for I := 0 to InitTrackCount - 1 do begin
|
|---|
| 49 | MetroLine := Engine.GetSelectedOrUnusedMetroLine;
|
|---|
| 50 | MetroLine.ConnectStation(Engine.Stations[0], nil, nil);
|
|---|
| 51 | MetroLine.ConnectStation(Engine.Stations[1], MetroLine.LineStations.Last, nil);
|
|---|
| 52 | end;
|
|---|
| 53 | UsedLines := 0;
|
|---|
| 54 | for I := 0 to Engine.Lines.Count - 1 do
|
|---|
| 55 | if Engine.Lines[I].LineStations.Count > 0 then Inc(UsedLines);
|
|---|
| 56 | Evaluate(UsedLines = InitTrackCount);
|
|---|
| 57 | Exit;
|
|---|
| 58 | end;
|
|---|
| 59 | for I := 0 to 100 do
|
|---|
| 60 | Engine.Tick;
|
|---|
| 61 | Pass;
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | constructor TTestCaseRun.Create;
|
|---|
| 65 | begin
|
|---|
| 66 | inherited;
|
|---|
| 67 | Engine := TEngine.Create(nil);
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | destructor TTestCaseRun.Destroy;
|
|---|
| 71 | begin
|
|---|
| 72 | FreeAndNil(Engine);
|
|---|
| 73 | end;
|
|---|
| 74 |
|
|---|
| 75 | end.
|
|---|
| 76 |
|
|---|