2023-12-05 17:21:21 +01:00
|
|
|
{
|
|
|
|
Solutions to the Advent Of Code.
|
|
|
|
Copyright (C) 2023 Stefan Müller
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
}
|
|
|
|
|
|
|
|
unit UTrebuchetTestCases;
|
|
|
|
|
|
|
|
{$mode ObjFPC}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UTrebuchet;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
|
|
{ TTrebuchetFullDataTestCase }
|
|
|
|
|
|
|
|
TTrebuchetFullDataTestCase = class(TEngineBaseTest)
|
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
|
|
|
published
|
|
|
|
procedure TestPart1;
|
|
|
|
procedure TestPart2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TTrebuchetExampleTestCase }
|
|
|
|
|
|
|
|
TTrebuchetExampleTestCase = class(TExampleEngineBaseTest)
|
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
|
|
|
published
|
|
|
|
procedure TestPart1;
|
|
|
|
end;
|
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
{ TExample2Trebuchet }
|
2023-12-05 17:21:21 +01:00
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
TExample2Trebuchet = class(TTrebuchet)
|
2023-12-05 17:21:21 +01:00
|
|
|
function GetDataFileName: string; override;
|
|
|
|
end;
|
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
{ TTrebuchetExample2TestCase }
|
2023-12-05 17:21:21 +01:00
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
TTrebuchetExample2TestCase = class(TExampleEngineBaseTest)
|
2023-12-05 17:21:21 +01:00
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
|
|
|
published
|
|
|
|
procedure TestPart2;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
{ TTrebuchetFullDataTestCase }
|
|
|
|
|
|
|
|
function TTrebuchetFullDataTestCase.CreateSolver: ISolver;
|
|
|
|
begin
|
|
|
|
Result := TTrebuchet.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTrebuchetFullDataTestCase.TestPart1;
|
|
|
|
begin
|
|
|
|
AssertEquals(56506, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTrebuchetFullDataTestCase.TestPart2;
|
|
|
|
begin
|
|
|
|
AssertEquals(56017, FSolver.GetResultPart2);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TTrebuchetExampleTestCase }
|
|
|
|
|
|
|
|
function TTrebuchetExampleTestCase.CreateSolver: ISolver;
|
|
|
|
begin
|
|
|
|
Result := TTrebuchet.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TTrebuchetExampleTestCase.TestPart1;
|
|
|
|
begin
|
|
|
|
AssertEquals(142, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
{ TExample2Trebuchet }
|
2023-12-05 17:21:21 +01:00
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
function TExample2Trebuchet.GetDataFileName: string;
|
2023-12-05 17:21:21 +01:00
|
|
|
begin
|
2024-02-22 22:54:45 +01:00
|
|
|
Result := 'trebuchet2.txt';
|
2023-12-05 17:21:21 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
{ TTrebuchetExample2TestCase }
|
2023-12-05 17:21:21 +01:00
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
function TTrebuchetExample2TestCase.CreateSolver: ISolver;
|
2023-12-05 17:21:21 +01:00
|
|
|
begin
|
2023-12-09 01:00:36 +01:00
|
|
|
Result := TExample2Trebuchet.Create;
|
2023-12-05 17:21:21 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-09 01:00:36 +01:00
|
|
|
procedure TTrebuchetExample2TestCase.TestPart2;
|
2023-12-05 17:21:21 +01:00
|
|
|
begin
|
|
|
|
AssertEquals(281, FSolver.GetResultPart2);
|
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
2024-06-10 20:24:05 +02:00
|
|
|
RegisterTest('TTrebuchet', TTrebuchetFullDataTestCase);
|
|
|
|
RegisterTest('TTrebuchet', TTrebuchetExampleTestCase);
|
|
|
|
RegisterTest('TTrebuchet', TTrebuchetExample2TestCase);
|
2023-12-05 17:21:21 +01:00
|
|
|
end.
|