Refactored test cases
This commit is contained in:
parent
9c4fb8b63a
commit
5bfbc83b13
|
@ -44,6 +44,10 @@
|
|||
<Filename Value="..\USolver.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="UBaseTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
|
|
@ -3,7 +3,7 @@ program AdventOfCodeFPCUnit;
|
|||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Interfaces, Forms, GuiTestRunner, UGearRatiosTestCases, USolver;
|
||||
Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UGearRatiosTestCases;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
{
|
||||
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 UBaseTestCases;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, USolver;
|
||||
|
||||
type
|
||||
|
||||
{ TBaseTestCase }
|
||||
|
||||
TBaseTestCase = class(TTestCase)
|
||||
protected
|
||||
FEngine: TSolverEngine;
|
||||
FSolver: ISolver;
|
||||
procedure Setup; override;
|
||||
procedure TearDown; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TBaseTestCase }
|
||||
|
||||
procedure TBaseTestCase.Setup;
|
||||
begin
|
||||
inherited Setup;
|
||||
FEngine := TSolverEngine.Create(ConcatPaths(['..', '..', 'bin', 'data']));
|
||||
end;
|
||||
|
||||
procedure TBaseTestCase.TearDown;
|
||||
begin
|
||||
FSolver.Free;
|
||||
FEngine.Free;
|
||||
inherited TearDown;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
|
@ -22,38 +22,27 @@ unit UGearRatiosTestCases;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, USolver, UGearRatios;
|
||||
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UGearRatios;
|
||||
|
||||
type
|
||||
|
||||
{ TGearRatiosBaseTestCase }
|
||||
|
||||
TGearRatiosBaseTestCase = class(TTestCase)
|
||||
TGearRatiosBaseTestCase = class(TBaseTestCase)
|
||||
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;
|
||||
procedure TestPart2;
|
||||
end;
|
||||
|
||||
{ TGearRatiosTestCase }
|
||||
|
||||
TGearRatiosTestCase = class(TGearRatiosBaseTestCase)
|
||||
published
|
||||
procedure TestEndOfLineNumber;
|
||||
end;
|
||||
|
||||
{ TGearRatiosExampleTestCase }
|
||||
|
||||
TGearRatiosExampleTestCase = class(TGearRatiosBaseTestCase)
|
||||
|
@ -64,35 +53,31 @@ type
|
|||
procedure TestPart2;
|
||||
end;
|
||||
|
||||
{ TGearRatiosTestCase }
|
||||
|
||||
TGearRatiosTestCase = class(TGearRatiosBaseTestCase)
|
||||
published
|
||||
procedure TestEndOfLineNumber;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TGearRatiosBaseTestCase }
|
||||
|
||||
procedure TGearRatiosBaseTestCase.Setup;
|
||||
begin
|
||||
inherited Setup;
|
||||
FSolver := TGearRatios.Create;
|
||||
end;
|
||||
|
||||
procedure TGearRatiosBaseTestCase.TearDown;
|
||||
begin
|
||||
FSolver.Free;
|
||||
end;
|
||||
|
||||
{ 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);
|
||||
|
@ -103,17 +88,6 @@ begin
|
|||
AssertEquals(80253814, FSolver.GetResultPart2);
|
||||
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;
|
||||
|
@ -143,9 +117,19 @@ begin
|
|||
AssertEquals(467835, FSolver.GetResultPart2);
|
||||
end;
|
||||
|
||||
{ TGearRatiosTestCase }
|
||||
|
||||
procedure TGearRatiosTestCase.TestEndOfLineNumber;
|
||||
begin
|
||||
FSolver.Init;
|
||||
FSolver.ProcessDataLine('...$541');
|
||||
FSolver.Finish;
|
||||
AssertEquals('Result of part 1 calculation incorrect.', 541, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterTest(TGearRatiosFullDataTestCase);
|
||||
RegisterTest(TGearRatiosTestCase);
|
||||
RegisterTest(TGearRatiosExampleTestCase);
|
||||
RegisterTest(TGearRatiosTestCase);
|
||||
end.
|
||||
|
|
|
@ -8,18 +8,18 @@ Height=663
|
|||
All Tests.Checked=1
|
||||
All Tests.Expanded=1
|
||||
TGearRatiosFullDataTestCase.Checked=1
|
||||
TGearRatiosFullDataTestCase.Expanded=1
|
||||
TGearRatiosFullDataTestCase.Expanded=0
|
||||
TGearRatiosFullDataTestCase.TestPart1.Checked=1
|
||||
TGearRatiosFullDataTestCase.TestPart1.Expanded=0
|
||||
TGearRatiosFullDataTestCase.TestPart2.Checked=1
|
||||
TGearRatiosFullDataTestCase.TestPart2.Expanded=0
|
||||
TGearRatiosTestCase.Checked=1
|
||||
TGearRatiosTestCase.Expanded=1
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Checked=1
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0
|
||||
TGearRatiosExampleTestCase.Checked=1
|
||||
TGearRatiosExampleTestCase.Expanded=1
|
||||
TGearRatiosExampleTestCase.Expanded=0
|
||||
TGearRatiosExampleTestCase.TestPart1.Checked=1
|
||||
TGearRatiosExampleTestCase.TestPart1.Expanded=0
|
||||
TGearRatiosExampleTestCase.TestPart2.Checked=1
|
||||
TGearRatiosExampleTestCase.TestPart2.Expanded=0
|
||||
TGearRatiosTestCase.Checked=1
|
||||
TGearRatiosTestCase.Expanded=0
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Checked=1
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0
|
||||
|
|
Loading…
Reference in New Issue