AdventOfCode2023/tests/UHotSpringsTestCases.pas

140 lines
3.2 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 UHotSpringsTestCases;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UHotSprings;
type
{ THotSpringsFullDataTestCase }
THotSpringsFullDataTestCase = class(TEngineBaseTest)
protected
function CreateSolver: ISolver; override;
published
procedure TestPart1;
end;
{ THotSpringsExampleTestCase }
THotSpringsExampleTestCase = class(TExampleEngineBaseTest)
protected
function CreateSolver: ISolver; override;
published
procedure TestPart1;
end;
{ THotSpringsTestCase }
THotSpringsTestCase = class(TSolverTestCase)
protected
function CreateSolver: ISolver; override;
procedure TestSingleLine(const ALine: string; const AValue: Integer);
published
procedure TestExampleLine1;
procedure TestExampleLine2;
procedure TestExampleLine3;
procedure TestExampleLine4;
procedure TestExampleLine5;
procedure TestExampleLine6;
end;
implementation
{ THotSpringsFullDataTestCase }
function THotSpringsFullDataTestCase.CreateSolver: ISolver;
begin
Result := THotSprings.Create;
end;
procedure THotSpringsFullDataTestCase.TestPart1;
begin
AssertEquals(7344, FSolver.GetResultPart1);
end;
{ THotSpringsExampleTestCase }
function THotSpringsExampleTestCase.CreateSolver: ISolver;
begin
Result := THotSprings.Create;
end;
procedure THotSpringsExampleTestCase.TestPart1;
begin
AssertEquals(21, FSolver.GetResultPart1);
end;
{ THotSpringsTestCase }
function THotSpringsTestCase.CreateSolver: ISolver;
begin
Result := THotSprings.Create;
end;
procedure THotSpringsTestCase.TestSingleLine(const ALine: string; const AValue: Integer);
begin
FSolver.Init;
FSolver.ProcessDataLine(ALine);
FSolver.Finish;
AssertEquals(AValue, FSolver.GetResultPart1);
end;
procedure THotSpringsTestCase.TestExampleLine1;
begin
TestSingleLine('???.### 1,1,3', 1);
end;
procedure THotSpringsTestCase.TestExampleLine2;
begin
TestSingleLine('.??..??...?##. 1,1,3', 4);
end;
procedure THotSpringsTestCase.TestExampleLine3;
begin
TestSingleLine('?#?#?#?#?#?#?#? 1,3,1,6', 1);
end;
procedure THotSpringsTestCase.TestExampleLine4;
begin
TestSingleLine('????.#...#... 4,1,1', 1);
end;
procedure THotSpringsTestCase.TestExampleLine5;
begin
TestSingleLine('????.######..#####. 1,6,5', 4);
end;
procedure THotSpringsTestCase.TestExampleLine6;
begin
TestSingleLine('?###???????? 3,2,1', 10);
end;
initialization
RegisterTest(THotSpringsFullDataTestCase);
RegisterTest(THotSpringsExampleTestCase);
RegisterTest(THotSpringsTestCase);
end.