Changeset 342 for trunk/Tests.pas


Ignore:
Timestamp:
Dec 22, 2024, 10:52:26 AM (15 hours ago)
Author:
chronos
Message:
  • Added: More tests.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tests.pas

    r336 r342  
    1717  end;
    1818
     19  { TTestCaseMap }
     20
     21  TTestCaseMap = class(TTestCase)
     22    Game: TGame;
     23    procedure Run; override;
     24    constructor Create; override;
     25    destructor Destroy; override;
     26  end;
     27
    1928function GetTestCases: TTestCases;
    2029
    2130
    2231implementation
     32
     33uses
     34  Geometry, MapType, Map;
    2335
    2436function GetTestCases: TTestCases;
     
    2739  with Result do begin
    2840    with TTestCaseGame(AddNew('Load and save', TTestCaseGame)) do begin
    29 
     41    end;
     42    with TTestCaseMap(AddNew('Map cells connection', TTestCaseMap)) do begin
    3043    end;
    3144  end;
     
    4457  Game2.LoadFromFile(FileName);
    4558  Evaluate(Game2.Compare(Game));
     59  Log := 'Game1: ' + LineEnding + Game.ToString + LineEnding +
     60    'Game2: ' + LineEnding + Game2.ToString + LineEnding;
    4661  Game2.Free;
    4762end;
     
    5974end;
    6075
     76{ TTestCaseMap }
     77
     78procedure TTestCaseMap.Run;
     79var
     80  X, Y: Integer;
     81  Connected: Boolean;
     82  Cell: TCell;
     83  Expected: Integer;
     84const
     85  Size = 10;
     86begin
     87  Connected := True;
     88  Game.Map.Size := TPoint.Create(Size, Size);
     89  Game.MapType := mtSquare;
     90  Game.New;
     91  for Y := 0 to Size - 1 do
     92  for X := 0 to Size - 1 do begin
     93    Cell := Game.Map.Cells[X + Y * Size];
     94    Expected := 4;
     95    if (X = 0) or (X = Size - 1) then Dec(Expected);
     96    if (Y = 0) or (Y = Size - 1) then Dec(Expected);
     97    if Cell.Neighbors.Count <> Expected then begin
     98      Log := Log + 'Cell ' + IntToStr(X + Y * Size) + ' expected neighbors count ' +
     99        IntToStr(Expected) + ' but is ' + IntToStr(Cell.Neighbors.Count) + LineEnding;
     100      if not Connected then Break;
     101    end;
     102  end;
     103  Evaluate(Connected);
     104end;
     105
     106constructor TTestCaseMap.Create;
     107begin
     108  inherited;
     109  Game := TGame.Create;
     110end;
     111
     112destructor TTestCaseMap.Destroy;
     113begin
     114  FreeAndNil(Game);
     115  inherited;
     116end;
     117
    61118end.
    62119
Note: See TracChangeset for help on using the changeset viewer.