diff --git a/tests/AdventOfCodeFPCUnit.lpi b/tests/AdventOfCodeFPCUnit.lpi index 6a82f6b..4a9673f 100644 --- a/tests/AdventOfCodeFPCUnit.lpi +++ b/tests/AdventOfCodeFPCUnit.lpi @@ -56,6 +56,14 @@ + + + + + + + + diff --git a/tests/AdventOfCodeFPCUnit.lpr b/tests/AdventOfCodeFPCUnit.lpr index 65174d4..e21dae5 100644 --- a/tests/AdventOfCodeFPCUnit.lpr +++ b/tests/AdventOfCodeFPCUnit.lpr @@ -3,8 +3,8 @@ program AdventOfCodeFPCUnit; {$mode objfpc}{$H+} uses - Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UGearRatiosTestCases, UScratchcardsTestCases, -UGiveSeedFertilizerTestCases; + Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UTrebuchetTestCases, UCubeConundrumTestCases, + UGearRatiosTestCases, UScratchcardsTestCases, UGiveSeedFertilizerTestCases; {$R *.res} diff --git a/tests/UCubeConundrumTestCases.pas b/tests/UCubeConundrumTestCases.pas new file mode 100644 index 0000000..3dddc95 --- /dev/null +++ b/tests/UCubeConundrumTestCases.pas @@ -0,0 +1,89 @@ +{ + 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 . +} + +unit UCubeConundrumTestCases; + +{$mode ObjFPC}{$H+} + +interface + +uses + Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UCubeConundrum; + +type + + { TCubeConundrumFullDataTestCase } + + TCubeConundrumFullDataTestCase = class(TEngineBaseTest) + protected + function CreateSolver: ISolver; override; + published + procedure TestPart1; + procedure TestPart2; + end; + + { TCubeConundrumExampleTestCase } + + TCubeConundrumExampleTestCase = class(TExampleEngineBaseTest) + protected + function CreateSolver: ISolver; override; + published + procedure TestPart1; + procedure TestPart2; + end; + +implementation + +{ TCubeConundrumFullDataTestCase } + +function TCubeConundrumFullDataTestCase.CreateSolver: ISolver; +begin + Result := TCubeConundrum.Create; +end; + +procedure TCubeConundrumFullDataTestCase.TestPart1; +begin + AssertEquals(2563, FSolver.GetResultPart1); +end; + +procedure TCubeConundrumFullDataTestCase.TestPart2; +begin + AssertEquals(70768, FSolver.GetResultPart2); +end; + +{ TCubeConundrumExampleTestCase } + +function TCubeConundrumExampleTestCase.CreateSolver: ISolver; +begin + Result := TCubeConundrum.Create; +end; + +procedure TCubeConundrumExampleTestCase.TestPart1; +begin + AssertEquals(8, FSolver.GetResultPart1); +end; + +procedure TCubeConundrumExampleTestCase.TestPart2; +begin + AssertEquals(2286, FSolver.GetResultPart2); +end; + +initialization + + RegisterTest(TCubeConundrumFullDataTestCase); + RegisterTest(TCubeConundrumExampleTestCase); +end. diff --git a/tests/UTrebuchetTestCases.pas b/tests/UTrebuchetTestCases.pas new file mode 100644 index 0000000..f74afdd --- /dev/null +++ b/tests/UTrebuchetTestCases.pas @@ -0,0 +1,118 @@ +{ + 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 . +} + +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; + + { TPart2ExampleTrebuchet } + + TPart2ExampleTrebuchet = class(TTrebuchet) + function GetDataFileName: string; override; + end; + + { TTrebuchetPart2ExampleTestCase } + + TTrebuchetPart2ExampleTestCase = class(TExampleEngineBaseTest) + 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; + +{ TPart2ExampleTrebuchet } + +function TPart2ExampleTrebuchet.GetDataFileName: string; +begin + Result := 'trebuchet_calibration_document2.txt'; +end; + +{ TTrebuchetPart2ExampleTestCase } + +function TTrebuchetPart2ExampleTestCase.CreateSolver: ISolver; +begin + Result := TPart2ExampleTrebuchet.Create; +end; + +procedure TTrebuchetPart2ExampleTestCase.TestPart2; +begin + AssertEquals(281, FSolver.GetResultPart2); +end; + +initialization + + RegisterTest(TTrebuchetFullDataTestCase); + RegisterTest(TTrebuchetExampleTestCase); + RegisterTest(TTrebuchetPart2ExampleTestCase); +end.