From 015b823376dc936b3d0982d403ddd04269c656d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 4 Dec 2023 16:32:48 +0100 Subject: [PATCH] Updated test cases for "Day 3: Gear Ratios" --- tests/UGearRatiosTestCases.pas | 89 +++++++++++++++++++---- tests/bin/AdventOfCodeFPCUnit.fpcunit.ini | 22 +++--- 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/tests/UGearRatiosTestCases.pas b/tests/UGearRatiosTestCases.pas index 54d1036..14817db 100644 --- a/tests/UGearRatiosTestCases.pas +++ b/tests/UGearRatiosTestCases.pas @@ -22,38 +22,96 @@ unit UGearRatiosTestCases; interface uses - Classes, SysUtils, fpcunit, testregistry, UGearRatios; + Classes, SysUtils, fpcunit, testregistry, USolver, UGearRatios; type - { TGearRatiosTestCase } + { TGearRatiosBaseTestCase } - TGearRatiosTestCase = class(TTestCase) + TGearRatiosBaseTestCase = class(TTestCase) protected FSolver: TGearRatios; procedure Setup; override; procedure TearDown; override; + end; + + { TGearRatiosFullDataTestCase } + + TGearRatiosFullDataTestCase = class(TGearRatiosBaseTestCase) + protected + FEngine: TSolverEngine; + procedure Setup; override; + procedure TearDown; override; + published + procedure TestPart1; + end; + + { TGearRatiosTestCase } + + TGearRatiosTestCase = class(TGearRatiosBaseTestCase) published - procedure TestPuzzleExample; procedure TestEndOfLineNumber; end; + { TGearRatiosExampleTestCase } + + TGearRatiosExampleTestCase = class(TGearRatiosBaseTestCase) + protected + procedure Setup; override; + published + procedure TestPart1; + procedure TestPart2; + end; + implementation -{ TGearRatiosTestCase } +{ TGearRatiosBaseTestCase } -procedure TGearRatiosTestCase.Setup; +procedure TGearRatiosBaseTestCase.Setup; begin FSolver := TGearRatios.Create; end; -procedure TGearRatiosTestCase.TearDown; +procedure TGearRatiosBaseTestCase.TearDown; begin FSolver.Free; end; -procedure TGearRatiosTestCase.TestPuzzleExample; +{ TGearRatiosFullDataTestCase } + +procedure TGearRatiosFullDataTestCase.Setup; begin + inherited Setup; + FEngine := TSolverEngine.Create(ConcatPaths(['..', '..', 'bin', 'data'])); + FEngine.ProcessData(FSolver); +end; + +procedure TGearRatiosFullDataTestCase.TearDown; +begin + FEngine.Free; + inherited TearDown; +end; + +procedure TGearRatiosFullDataTestCase.TestPart1; +begin + AssertEquals(530495, FSolver.GetResultPart1); +end; + +{ TGearRatiosTestCase } + +procedure TGearRatiosTestCase.TestEndOfLineNumber; +begin + FSolver.Init; + FSolver.ProcessDataLine('...$541'); + FSolver.Finish; + AssertEquals('Result of part 1 calculation incorrect.', 541, FSolver.GetResultPart1); +end; + +{ TGearRatiosExampleTestCase } + +procedure TGearRatiosExampleTestCase.Setup; +begin + inherited Setup; FSolver.Init; FSolver.ProcessDataLine('467..114..'); FSolver.ProcessDataLine('...*......'); @@ -66,18 +124,21 @@ begin FSolver.ProcessDataLine('...$.*....'); FSolver.ProcessDataLine('.664.598..'); FSolver.Finish; - AssertEquals('Result of part 1 calculation incorrect.', 4361, FSolver.GetResultPart1); end; -procedure TGearRatiosTestCase.TestEndOfLineNumber; +procedure TGearRatiosExampleTestCase.TestPart1; begin - FSolver.Init; - FSolver.ProcessDataLine('...$541'); - FSolver.Finish; - AssertEquals('Result of part 1 calculation incorrect.', 541, FSolver.GetResultPart1); + AssertEquals(4361, FSolver.GetResultPart1); +end; + +procedure TGearRatiosExampleTestCase.TestPart2; +begin + AssertEquals(467835, FSolver.GetResultPart2); end; initialization + RegisterTest(TGearRatiosFullDataTestCase); RegisterTest(TGearRatiosTestCase); + RegisterTest(TGearRatiosExampleTestCase); end. diff --git a/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini b/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini index f1640aa..cc80332 100644 --- a/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini +++ b/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini @@ -7,19 +7,17 @@ Height=663 [Tests] All Tests.Checked=1 All Tests.Expanded=1 -TGearRatiosEngineTestCase.Checked=1 -TGearRatiosEngineTestCase.Expanded=1 -TGearRatiosEngineTestCase.TestFullDataPart1.Checked=1 -TGearRatiosEngineTestCase.TestFullDataPart1.Expanded=0 -TGearRatiosEngineTestCase.TestFullDataPart2.Checked=1 -TGearRatiosEngineTestCase.TestFullDataPart2.Expanded=0 +TGearRatiosFullDataTestCase.Checked=1 +TGearRatiosFullDataTestCase.Expanded=1 +TGearRatiosFullDataTestCase.TestPart1.Checked=1 +TGearRatiosFullDataTestCase.TestPart1.Expanded=0 TGearRatiosTestCase.Checked=1 TGearRatiosTestCase.Expanded=1 TGearRatiosTestCase.TestEndOfLineNumber.Checked=1 TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0 -TGearRatiosPuzzleExampleTestCase.Checked=1 -TGearRatiosPuzzleExampleTestCase.Expanded=1 -TGearRatiosPuzzleExampleTestCase.TestPart1.Checked=1 -TGearRatiosPuzzleExampleTestCase.TestPart1.Expanded=0 -TGearRatiosPuzzleExampleTestCase.TestPart2.Checked=1 -TGearRatiosPuzzleExampleTestCase.TestPart2.Expanded=0 +TGearRatiosExampleTestCase.Checked=1 +TGearRatiosExampleTestCase.Expanded=1 +TGearRatiosExampleTestCase.TestPart1.Checked=1 +TGearRatiosExampleTestCase.TestPart1.Expanded=0 +TGearRatiosExampleTestCase.TestPart2.Checked=1 +TGearRatiosExampleTestCase.TestPart2.Expanded=0