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
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.

View File

@ -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