2023-12-12 15:47:58 +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 UHotSpringsTestCases;
|
|
|
|
|
|
|
|
{$mode ObjFPC}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UHotSprings;
|
|
|
|
|
|
|
|
type
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
{ THotSpringsFullDataTestCase }
|
|
|
|
|
|
|
|
THotSpringsFullDataTestCase = class(TEngineBaseTest)
|
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
|
|
|
published
|
|
|
|
procedure TestPart1;
|
|
|
|
procedure TestPart2;
|
|
|
|
end;
|
|
|
|
|
2023-12-12 15:47:58 +01:00
|
|
|
{ THotSpringsExampleTestCase }
|
|
|
|
|
|
|
|
THotSpringsExampleTestCase = class(TExampleEngineBaseTest)
|
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
|
|
|
published
|
|
|
|
procedure TestPart1;
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure TestPart2;
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ THotSpringsTestCase }
|
|
|
|
|
|
|
|
THotSpringsTestCase = class(TSolverTestCase)
|
|
|
|
protected
|
|
|
|
function CreateSolver: ISolver; override;
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure TestSingleLine(const ALine: string);
|
2023-12-12 15:47:58 +01:00
|
|
|
published
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure TestExampleLine1Part1;
|
|
|
|
procedure TestExampleLine2Part1;
|
|
|
|
procedure TestExampleLine3Part1;
|
|
|
|
procedure TestExampleLine4Part1;
|
|
|
|
procedure TestExampleLine5Part1;
|
|
|
|
procedure TestExampleLine6Part1;
|
|
|
|
procedure TestExampleLine1Part2;
|
|
|
|
procedure TestExampleLine2Part2;
|
|
|
|
procedure TestExampleLine3Part2;
|
|
|
|
procedure TestExampleLine4Part2;
|
|
|
|
procedure TestExampleLine5Part2;
|
|
|
|
procedure TestExampleLine6Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsFullDataTestCase.TestPart2;
|
|
|
|
begin
|
|
|
|
AssertEquals(-1, FSolver.GetResultPart2);
|
|
|
|
end;
|
|
|
|
|
2023-12-12 15:47:58 +01:00
|
|
|
{ THotSpringsExampleTestCase }
|
|
|
|
|
|
|
|
function THotSpringsExampleTestCase.CreateSolver: ISolver;
|
|
|
|
begin
|
|
|
|
Result := THotSprings.Create;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsExampleTestCase.TestPart1;
|
|
|
|
begin
|
|
|
|
AssertEquals(21, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsExampleTestCase.TestPart2;
|
|
|
|
begin
|
|
|
|
AssertEquals(525152, FSolver.GetResultPart2);
|
|
|
|
end;
|
|
|
|
|
2023-12-12 15:47:58 +01:00
|
|
|
{ THotSpringsTestCase }
|
|
|
|
|
|
|
|
function THotSpringsTestCase.CreateSolver: ISolver;
|
|
|
|
begin
|
|
|
|
Result := THotSprings.Create;
|
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestSingleLine(const ALine: string);
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
|
|
|
FSolver.Init;
|
|
|
|
FSolver.ProcessDataLine(ALine);
|
|
|
|
FSolver.Finish;
|
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine1Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('???.### 1,1,3');
|
|
|
|
AssertEquals(1, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine2Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('.??..??...?##. 1,1,3');
|
|
|
|
AssertEquals(4, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine3Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('?#?#?#?#?#?#?#? 1,3,1,6');
|
|
|
|
AssertEquals(1, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine4Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('????.#...#... 4,1,1');
|
|
|
|
AssertEquals(1, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine5Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('????.######..#####. 1,6,5');
|
|
|
|
AssertEquals(4, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine6Part1;
|
|
|
|
begin
|
|
|
|
TestSingleLine('?###???????? 3,2,1');
|
|
|
|
AssertEquals(10, FSolver.GetResultPart1);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure THotSpringsTestCase.TestExampleLine1Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('???.### 1,1,3');
|
|
|
|
AssertEquals(1, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine2Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('.??..??...?##. 1,1,3');
|
|
|
|
AssertEquals(16384, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine3Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('?#?#?#?#?#?#?#? 1,3,1,6');
|
|
|
|
AssertEquals(1, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine4Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('????.#...#... 4,1,1');
|
|
|
|
AssertEquals(16, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine5Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('????.######..#####. 1,6,5');
|
|
|
|
AssertEquals(2500, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
2023-12-13 12:32:12 +01:00
|
|
|
procedure THotSpringsTestCase.TestExampleLine6Part2;
|
2023-12-12 15:47:58 +01:00
|
|
|
begin
|
2023-12-13 12:32:12 +01:00
|
|
|
TestSingleLine('?###???????? 3,2,1');
|
|
|
|
AssertEquals(506250, FSolver.GetResultPart2);
|
2023-12-12 15:47:58 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
initialization
|
|
|
|
|
2024-06-10 20:24:05 +02:00
|
|
|
RegisterTest('THotSprings', THotSpringsExampleTestCase);
|
|
|
|
RegisterTest('THotSprings', THotSpringsTestCase);
|
2023-12-12 15:47:58 +01:00
|
|
|
end.
|
|
|
|
|