Added solution for "Day 24: Never Tell Me The Odds", part 1
This commit is contained in:
@@ -136,6 +136,10 @@
|
||||
<Filename Value="ULongWalkTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="UNeverTellMeTheOddsTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
||||
@@ -8,7 +8,8 @@ uses
|
||||
UHauntedWastelandTestCases, UMirageMaintenanceTestCases, UPipeMazeTestCases, UCosmicExpansionTestCases,
|
||||
UHotSpringsTestCases, UPointOfIncidenceTestCases, UParabolicReflectorDishTestCases, ULensLibraryTestCases,
|
||||
UFloorWillBeLavaTestCases, UClumsyCrucibleTestCases, ULavaductLagoonTestCases, UAplentyTestCases,
|
||||
UPulsePropagationTestCases, UStepCounterTestCases, USandSlabsTestCases, ULongWalkTestCases;
|
||||
UPulsePropagationTestCases, UStepCounterTestCases, USandSlabsTestCases, ULongWalkTestCases,
|
||||
UNeverTellMeTheOddsTestCases;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
||||
173
tests/UNeverTellMeTheOddsTestCases.pas
Normal file
173
tests/UNeverTellMeTheOddsTestCases.pas
Normal file
@@ -0,0 +1,173 @@
|
||||
{
|
||||
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 UNeverTellMeTheOddsTestCases;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UNeverTellMeTheOdds;
|
||||
|
||||
type
|
||||
|
||||
{ TNeverTellMeTheOddsFullDataTestCase }
|
||||
|
||||
TNeverTellMeTheOddsFullDataTestCase = class(TEngineBaseTest)
|
||||
protected
|
||||
function CreateSolver: ISolver; override;
|
||||
published
|
||||
procedure TestPart1;
|
||||
end;
|
||||
|
||||
{ TNeverTellMeTheOddsExampleTestCase }
|
||||
|
||||
TNeverTellMeTheOddsExampleTestCase = class(TExampleEngineBaseTest)
|
||||
protected
|
||||
function CreateSolver: ISolver; override;
|
||||
published
|
||||
procedure TestPart1;
|
||||
end;
|
||||
|
||||
{ TNeverTellMeTheOddsTestCase }
|
||||
|
||||
TNeverTellMeTheOddsTestCase = class(TSolverTestCase)
|
||||
protected
|
||||
function CreateSolver: ISolver; override;
|
||||
procedure TestTwoLines(const ALine1, ALine2: string);
|
||||
published
|
||||
procedure TestExampleLines12;
|
||||
procedure TestExampleLines13;
|
||||
procedure TestExampleLines14;
|
||||
procedure TestExampleLines15;
|
||||
procedure TestExampleLines23;
|
||||
procedure TestExampleLines24;
|
||||
procedure TestExampleLines25;
|
||||
procedure TestExampleLines34;
|
||||
procedure TestExampleLines35;
|
||||
procedure TestExampleLines45;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TNeverTellMeTheOddsFullDataTestCase }
|
||||
|
||||
function TNeverTellMeTheOddsFullDataTestCase.CreateSolver: ISolver;
|
||||
begin
|
||||
Result := TNeverTellMeTheOdds.Create;
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsFullDataTestCase.TestPart1;
|
||||
begin
|
||||
AssertEquals(15107, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
{ TNeverTellMeTheOddsExampleTestCase }
|
||||
|
||||
function TNeverTellMeTheOddsExampleTestCase.CreateSolver: ISolver;
|
||||
begin
|
||||
Result := TNeverTellMeTheOdds.Create(7, 27);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsExampleTestCase.TestPart1;
|
||||
begin
|
||||
AssertEquals(2, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
{ TNeverTellMeTheOddsTestCase }
|
||||
|
||||
function TNeverTellMeTheOddsTestCase.CreateSolver: ISolver;
|
||||
begin
|
||||
Result := TNeverTellMeTheOdds.Create(7, 27);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestTwoLines(const ALine1, ALine2: string);
|
||||
begin
|
||||
FSolver.Init;
|
||||
FSolver.ProcessDataLine(ALine1);
|
||||
FSolver.ProcessDataLine(ALine2);
|
||||
FSolver.Finish;
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines12;
|
||||
begin
|
||||
TestTwoLines('19, 13, 30 @ -2, 1, -2', '18, 19, 22 @ -1, -1, -2');
|
||||
AssertEquals(1, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines13;
|
||||
begin
|
||||
TestTwoLines('19, 13, 30 @ -2, 1, -2', '20, 25, 34 @ -2, -2, -4');
|
||||
AssertEquals(1, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines14;
|
||||
begin
|
||||
TestTwoLines('19, 13, 30 @ -2, 1, -2', '12, 31, 28 @ -1, -2, -1');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines15;
|
||||
begin
|
||||
TestTwoLines('19, 13, 30 @ -2, 1, -2', '20, 19, 15 @ 1, -5, -3');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines23;
|
||||
begin
|
||||
TestTwoLines('18, 19, 22 @ -1, -1, -2', '20, 25, 34 @ -2, -2, -4');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines24;
|
||||
begin
|
||||
TestTwoLines('18, 19, 22 @ -1, -1, -2', '12, 31, 28 @ -1, -2, -1');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines25;
|
||||
begin
|
||||
TestTwoLines('18, 19, 22 @ -1, -1, -2', '20, 19, 15 @ 1, -5, -3');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines34;
|
||||
begin
|
||||
TestTwoLines('20, 25, 34 @ -2, -2, -4', '12, 31, 28 @ -1, -2, -1');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines35;
|
||||
begin
|
||||
TestTwoLines('20, 25, 34 @ -2, -2, -4', '20, 19, 15 @ 1, -5, -3');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TNeverTellMeTheOddsTestCase.TestExampleLines45;
|
||||
begin
|
||||
TestTwoLines('12, 31, 28 @ -1, -2, -1', '20, 19, 15 @ 1, -5, -3');
|
||||
AssertEquals(0, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterTest(TNeverTellMeTheOddsFullDataTestCase);
|
||||
RegisterTest(TNeverTellMeTheOddsExampleTestCase);
|
||||
RegisterTest(TNeverTellMeTheOddsTestCase);
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user