{ 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 { 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 GetDataPath: string; virtual; end; { TExampleEngineBaseTest } TExampleEngineBaseTest = class(TEngineBaseTest) protected function GetDataPath: string; 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; var fileName: string; begin inherited Setup; FEngine := TSolverEngine.Create(GetDataPath); fileName := FEngine.GetDataFileName(FSolver); AssertTrue('Cannot find puzzle input file ''' + ExpandFileName(fileName) + '''. ' + 'Please download the file from https://adventofcode.com/2023/', FileExists(fileName)); FEngine.ProcessData(FSolver); end; procedure TEngineBaseTest.TearDown; begin FEngine.Free; inherited TearDown; end; function TEngineBaseTest.GetDataPath: string; begin Result := ConcatPaths(['..', '..', 'bin', 'data']); end; { TExampleEngineBaseTest } function TExampleEngineBaseTest.GetDataPath: string; begin Result := 'example_data'; end; end.