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