AdventOfCode2023/tests/UBaseTestCases.pas

108 lines
2.4 KiB
Plaintext

{
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
{ TSolverTestCase }
TSolverTestCase = class(TTestCase)
protected
FSolver: ISolver;
procedure Setup; override;
procedure TearDown; override;
function CreateSolver: ISolver; virtual; abstract;
end;
{ TEngineBaseTest }
TEngineBaseTest = class(TSolverTestCase)
protected
FEngine: TSolverEngine;
procedure Setup; override;
procedure TearDown; override;
function GetDataPaths: TStringArray; virtual;
end;
{ TExampleEngineBaseTest }
TExampleEngineBaseTest = class(TEngineBaseTest)
protected
function GetDataPaths: TStringArray; override;
end;
implementation
{ TSolverTestCase }
procedure TSolverTestCase.Setup;
begin
inherited Setup;
FSolver := CreateSolver;
end;
procedure TSolverTestCase.TearDown;
begin
FSolver.Free;
inherited TearDown;
end;
{ TEngineBaseTest }
procedure TEngineBaseTest.Setup;
begin
inherited Setup;
FEngine := TSolverEngine.Create(GetDataPaths);
AssertTrue(FEngine.GetInvalidDataPathMessage(FSolver), FEngine.HasValidDataPath(FSolver));
FEngine.ProcessData(FSolver);
end;
procedure TEngineBaseTest.TearDown;
begin
FEngine.Free;
inherited TearDown;
end;
function TEngineBaseTest.GetDataPaths: TStringArray;
begin
Result := TStringArray.Create(
ConcatPaths(['..', '..', 'bin', 'data']),
ConcatPaths(['..', '..', '..', 'data'])
);
end;
{ TExampleEngineBaseTest }
function TExampleEngineBaseTest.GetDataPaths: TStringArray;
begin
Result := TStringArray.Create(
ConcatPaths(['..', '..', 'bin', 'data', 'example']),
ConcatPaths(['..', '..', '..', 'data', 'example'])
);
end;
end.