Changeset 342 for trunk/Tests.pas
- Timestamp:
- Dec 22, 2024, 10:52:26 AM (15 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tests.pas
r336 r342 17 17 end; 18 18 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 19 28 function GetTestCases: TTestCases; 20 29 21 30 22 31 implementation 32 33 uses 34 Geometry, MapType, Map; 23 35 24 36 function GetTestCases: TTestCases; … … 27 39 with Result do begin 28 40 with TTestCaseGame(AddNew('Load and save', TTestCaseGame)) do begin 29 41 end; 42 with TTestCaseMap(AddNew('Map cells connection', TTestCaseMap)) do begin 30 43 end; 31 44 end; … … 44 57 Game2.LoadFromFile(FileName); 45 58 Evaluate(Game2.Compare(Game)); 59 Log := 'Game1: ' + LineEnding + Game.ToString + LineEnding + 60 'Game2: ' + LineEnding + Game2.ToString + LineEnding; 46 61 Game2.Free; 47 62 end; … … 59 74 end; 60 75 76 { TTestCaseMap } 77 78 procedure TTestCaseMap.Run; 79 var 80 X, Y: Integer; 81 Connected: Boolean; 82 Cell: TCell; 83 Expected: Integer; 84 const 85 Size = 10; 86 begin 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); 104 end; 105 106 constructor TTestCaseMap.Create; 107 begin 108 inherited; 109 Game := TGame.Create; 110 end; 111 112 destructor TTestCaseMap.Destroy; 113 begin 114 FreeAndNil(Game); 115 inherited; 116 end; 117 61 118 end. 62 119
Note:
See TracChangeset
for help on using the changeset viewer.