AdventOfCode2023/tests/UNeverTellMeTheOddsTestCase...

174 lines
4.7 KiB
Plaintext

{
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.