diff --git a/tests/AdventOfCodeFPCUnit.lpi b/tests/AdventOfCodeFPCUnit.lpi
index 4b3c50c..fff5ccd 100644
--- a/tests/AdventOfCodeFPCUnit.lpi
+++ b/tests/AdventOfCodeFPCUnit.lpi
@@ -44,6 +44,10 @@
+
+
+
+
diff --git a/tests/AdventOfCodeFPCUnit.lpr b/tests/AdventOfCodeFPCUnit.lpr
index 6ba23fb..cb55c7b 100644
--- a/tests/AdventOfCodeFPCUnit.lpr
+++ b/tests/AdventOfCodeFPCUnit.lpr
@@ -3,7 +3,7 @@ program AdventOfCodeFPCUnit;
{$mode objfpc}{$H+}
uses
- Interfaces, Forms, GuiTestRunner, UGearRatiosTestCases, USolver;
+ Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UGearRatiosTestCases;
{$R *.res}
diff --git a/tests/UBaseTestCases.pas b/tests/UBaseTestCases.pas
new file mode 100644
index 0000000..57c8651
--- /dev/null
+++ b/tests/UBaseTestCases.pas
@@ -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 .
+}
+
+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.
+
diff --git a/tests/UGearRatiosTestCases.pas b/tests/UGearRatiosTestCases.pas
index 6568d86..1aa23a9 100644
--- a/tests/UGearRatiosTestCases.pas
+++ b/tests/UGearRatiosTestCases.pas
@@ -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.
diff --git a/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini b/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini
index c7501c6..87cc773 100644
--- a/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini
+++ b/tests/bin/AdventOfCodeFPCUnit.fpcunit.ini
@@ -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