Updated test cases for "Day 3: Gear Ratios"

This commit is contained in:
Stefan Müller 2023-12-04 16:32:48 +01:00 committed by Stefan Müller
parent 05e4944521
commit 015b823376
2 changed files with 85 additions and 26 deletions

View File

@ -22,38 +22,96 @@ unit UGearRatiosTestCases;
interface interface
uses uses
Classes, SysUtils, fpcunit, testregistry, UGearRatios; Classes, SysUtils, fpcunit, testregistry, USolver, UGearRatios;
type type
{ TGearRatiosTestCase } { TGearRatiosBaseTestCase }
TGearRatiosTestCase = class(TTestCase) TGearRatiosBaseTestCase = class(TTestCase)
protected protected
FSolver: TGearRatios; FSolver: TGearRatios;
procedure Setup; override; procedure Setup; override;
procedure TearDown; 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 published
procedure TestPuzzleExample;
procedure TestEndOfLineNumber; procedure TestEndOfLineNumber;
end; end;
{ TGearRatiosExampleTestCase }
TGearRatiosExampleTestCase = class(TGearRatiosBaseTestCase)
protected
procedure Setup; override;
published
procedure TestPart1;
procedure TestPart2;
end;
implementation implementation
{ TGearRatiosTestCase } { TGearRatiosBaseTestCase }
procedure TGearRatiosTestCase.Setup; procedure TGearRatiosBaseTestCase.Setup;
begin begin
FSolver := TGearRatios.Create; FSolver := TGearRatios.Create;
end; end;
procedure TGearRatiosTestCase.TearDown; procedure TGearRatiosBaseTestCase.TearDown;
begin begin
FSolver.Free; FSolver.Free;
end; end;
procedure TGearRatiosTestCase.TestPuzzleExample; { TGearRatiosFullDataTestCase }
procedure TGearRatiosFullDataTestCase.Setup;
begin 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.Init;
FSolver.ProcessDataLine('467..114..'); FSolver.ProcessDataLine('467..114..');
FSolver.ProcessDataLine('...*......'); FSolver.ProcessDataLine('...*......');
@ -66,18 +124,21 @@ begin
FSolver.ProcessDataLine('...$.*....'); FSolver.ProcessDataLine('...$.*....');
FSolver.ProcessDataLine('.664.598..'); FSolver.ProcessDataLine('.664.598..');
FSolver.Finish; FSolver.Finish;
AssertEquals('Result of part 1 calculation incorrect.', 4361, FSolver.GetResultPart1);
end; end;
procedure TGearRatiosTestCase.TestEndOfLineNumber; procedure TGearRatiosExampleTestCase.TestPart1;
begin begin
FSolver.Init; AssertEquals(4361, FSolver.GetResultPart1);
FSolver.ProcessDataLine('...$541'); end;
FSolver.Finish;
AssertEquals('Result of part 1 calculation incorrect.', 541, FSolver.GetResultPart1); procedure TGearRatiosExampleTestCase.TestPart2;
begin
AssertEquals(467835, FSolver.GetResultPart2);
end; end;
initialization initialization
RegisterTest(TGearRatiosFullDataTestCase);
RegisterTest(TGearRatiosTestCase); RegisterTest(TGearRatiosTestCase);
RegisterTest(TGearRatiosExampleTestCase);
end. end.

View File

@ -7,19 +7,17 @@ Height=663
[Tests] [Tests]
All Tests.Checked=1 All Tests.Checked=1
All Tests.Expanded=1 All Tests.Expanded=1
TGearRatiosEngineTestCase.Checked=1 TGearRatiosFullDataTestCase.Checked=1
TGearRatiosEngineTestCase.Expanded=1 TGearRatiosFullDataTestCase.Expanded=1
TGearRatiosEngineTestCase.TestFullDataPart1.Checked=1 TGearRatiosFullDataTestCase.TestPart1.Checked=1
TGearRatiosEngineTestCase.TestFullDataPart1.Expanded=0 TGearRatiosFullDataTestCase.TestPart1.Expanded=0
TGearRatiosEngineTestCase.TestFullDataPart2.Checked=1
TGearRatiosEngineTestCase.TestFullDataPart2.Expanded=0
TGearRatiosTestCase.Checked=1 TGearRatiosTestCase.Checked=1
TGearRatiosTestCase.Expanded=1 TGearRatiosTestCase.Expanded=1
TGearRatiosTestCase.TestEndOfLineNumber.Checked=1 TGearRatiosTestCase.TestEndOfLineNumber.Checked=1
TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0 TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0
TGearRatiosPuzzleExampleTestCase.Checked=1 TGearRatiosExampleTestCase.Checked=1
TGearRatiosPuzzleExampleTestCase.Expanded=1 TGearRatiosExampleTestCase.Expanded=1
TGearRatiosPuzzleExampleTestCase.TestPart1.Checked=1 TGearRatiosExampleTestCase.TestPart1.Checked=1
TGearRatiosPuzzleExampleTestCase.TestPart1.Expanded=0 TGearRatiosExampleTestCase.TestPart1.Expanded=0
TGearRatiosPuzzleExampleTestCase.TestPart2.Checked=1 TGearRatiosExampleTestCase.TestPart2.Checked=1
TGearRatiosPuzzleExampleTestCase.TestPart2.Expanded=0 TGearRatiosExampleTestCase.TestPart2.Expanded=0