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