Added custom constructors for TCosmicExpansion and TStepCounter to simplify test case setup
This commit is contained in:
parent
2bb89c952b
commit
c3ecaf59fa
|
@ -35,17 +35,17 @@ type
|
||||||
|
|
||||||
TCosmicExpansion = class(TSolver)
|
TCosmicExpansion = class(TSolver)
|
||||||
private
|
private
|
||||||
|
FExpansionFactor: Integer;
|
||||||
FColumnExpansion, FRowExpansion: specialize TList<Integer>;
|
FColumnExpansion, FRowExpansion: specialize TList<Integer>;
|
||||||
FGalaxies: specialize TList<TPoint>;
|
FGalaxies: specialize TList<TPoint>;
|
||||||
procedure InitColumnExpansion(const ASize: Integer);
|
procedure InitColumnExpansion(const ASize: Integer);
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create(const AExpansionFactor: Integer = 999999);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ProcessDataLine(const ALine: string); override;
|
procedure ProcessDataLine(const ALine: string); override;
|
||||||
procedure Finish; override;
|
procedure Finish; override;
|
||||||
function GetDataFileName: string; override;
|
function GetDataFileName: string; override;
|
||||||
function GetPuzzleName: string; override;
|
function GetPuzzleName: string; override;
|
||||||
function GetExpansionFactor: Integer; virtual;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
@ -64,8 +64,9 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCosmicExpansion.Create;
|
constructor TCosmicExpansion.Create(const AExpansionFactor: Integer);
|
||||||
begin
|
begin
|
||||||
|
FExpansionFactor := AExpansionFactor;
|
||||||
FColumnExpansion := specialize TList<Integer>.Create;
|
FColumnExpansion := specialize TList<Integer>.Create;
|
||||||
FRowExpansion := specialize TList<Integer>.Create;
|
FRowExpansion := specialize TList<Integer>.Create;
|
||||||
FGalaxies := specialize TList<TPoint>.Create;
|
FGalaxies := specialize TList<TPoint>.Create;
|
||||||
|
@ -110,12 +111,12 @@ begin
|
||||||
for k := Min(FGalaxies[i].X, FGalaxies[j].X) to Max(FGalaxies[i].X, FGalaxies[j].X) - 1 do
|
for k := Min(FGalaxies[i].X, FGalaxies[j].X) to Max(FGalaxies[i].X, FGalaxies[j].X) - 1 do
|
||||||
begin
|
begin
|
||||||
Inc(FPart1, 1 + FColumnExpansion[k]);
|
Inc(FPart1, 1 + FColumnExpansion[k]);
|
||||||
Inc(FPart2, 1 + FColumnExpansion[k] * GetExpansionFactor);
|
Inc(FPart2, 1 + FColumnExpansion[k] * FExpansionFactor);
|
||||||
end;
|
end;
|
||||||
for k := Min(FGalaxies[i].Y, FGalaxies[j].Y) + 1 to Max(FGalaxies[i].Y, FGalaxies[j].Y) do
|
for k := Min(FGalaxies[i].Y, FGalaxies[j].Y) + 1 to Max(FGalaxies[i].Y, FGalaxies[j].Y) do
|
||||||
begin
|
begin
|
||||||
Inc(FPart1, 1 + FRowExpansion[k]);
|
Inc(FPart1, 1 + FRowExpansion[k]);
|
||||||
Inc(FPart2, 1 + FRowExpansion[k] * GetExpansionFactor);
|
Inc(FPart2, 1 + FRowExpansion[k] * FExpansionFactor);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -130,10 +131,5 @@ begin
|
||||||
Result := 'Day 11: Cosmic Expansion';
|
Result := 'Day 11: Cosmic Expansion';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCosmicExpansion.GetExpansionFactor: Integer;
|
|
||||||
begin
|
|
||||||
Result := 999999;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,7 @@ type
|
||||||
function GetPosition(constref APoint: TPoint): Char;
|
function GetPosition(constref APoint: TPoint): Char;
|
||||||
procedure SetPosition(constref APoint: TPoint; const AValue: Char);
|
procedure SetPosition(constref APoint: TPoint; const AValue: Char);
|
||||||
public
|
public
|
||||||
property MaxSteps: Integer read FMaxSteps write FMaxSteps;
|
constructor Create(const AMaxSteps: Integer = 64);
|
||||||
constructor Create;
|
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure ProcessDataLine(const ALine: string); override;
|
procedure ProcessDataLine(const ALine: string); override;
|
||||||
procedure Finish; override;
|
procedure Finish; override;
|
||||||
|
@ -90,9 +89,9 @@ begin
|
||||||
FLines[APoint.Y] := s;
|
FLines[APoint.Y] := s;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TStepCounter.Create;
|
constructor TStepCounter.Create(const AMaxSteps: Integer);
|
||||||
begin
|
begin
|
||||||
FMaxSteps := 64;
|
FMaxSteps := AMaxSteps;
|
||||||
FLines := TStringList.Create;
|
FLines := TStringList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
@ -45,13 +45,6 @@ type
|
||||||
procedure TestPart1;
|
procedure TestPart1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFactor10CosmicExpansion }
|
|
||||||
|
|
||||||
TFactor10CosmicExpansion = class(TCosmicExpansion)
|
|
||||||
public
|
|
||||||
function GetExpansionFactor: Integer; override;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCosmicExpansionExampleFactor10TestCase }
|
{ TCosmicExpansionExampleFactor10TestCase }
|
||||||
|
|
||||||
TCosmicExpansionExampleFactor10TestCase = class(TExampleEngineBaseTest)
|
TCosmicExpansionExampleFactor10TestCase = class(TExampleEngineBaseTest)
|
||||||
|
@ -61,12 +54,6 @@ type
|
||||||
procedure TestPart2;
|
procedure TestPart2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFactor100CosmicExpansion }
|
|
||||||
|
|
||||||
TFactor100CosmicExpansion = class(TCosmicExpansion)
|
|
||||||
function GetExpansionFactor: Integer; override;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCosmicExpansionExampleFactor100TestCase }
|
{ TCosmicExpansionExampleFactor100TestCase }
|
||||||
|
|
||||||
TCosmicExpansionExampleFactor100TestCase = class(TExampleEngineBaseTest)
|
TCosmicExpansionExampleFactor100TestCase = class(TExampleEngineBaseTest)
|
||||||
|
@ -107,18 +94,11 @@ begin
|
||||||
AssertEquals(374, FSolver.GetResultPart1);
|
AssertEquals(374, FSolver.GetResultPart1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFactor10CosmicExpansion }
|
|
||||||
|
|
||||||
function TFactor10CosmicExpansion.GetExpansionFactor: Integer;
|
|
||||||
begin
|
|
||||||
Result := 9;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCosmicExpansionExampleFactor10TestCase }
|
{ TCosmicExpansionExampleFactor10TestCase }
|
||||||
|
|
||||||
function TCosmicExpansionExampleFactor10TestCase.CreateSolver: ISolver;
|
function TCosmicExpansionExampleFactor10TestCase.CreateSolver: ISolver;
|
||||||
begin
|
begin
|
||||||
Result := TFactor10CosmicExpansion.Create;
|
Result := TCosmicExpansion.Create(9);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCosmicExpansionExampleFactor10TestCase.TestPart2;
|
procedure TCosmicExpansionExampleFactor10TestCase.TestPart2;
|
||||||
|
@ -126,18 +106,11 @@ begin
|
||||||
AssertEquals(1030, FSolver.GetResultPart2);
|
AssertEquals(1030, FSolver.GetResultPart2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TFactor100CosmicExpansion }
|
|
||||||
|
|
||||||
function TFactor100CosmicExpansion.GetExpansionFactor: Integer;
|
|
||||||
begin
|
|
||||||
Result := 99;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCosmicExpansionExampleFactor100TestCase }
|
{ TCosmicExpansionExampleFactor100TestCase }
|
||||||
|
|
||||||
function TCosmicExpansionExampleFactor100TestCase.CreateSolver: ISolver;
|
function TCosmicExpansionExampleFactor100TestCase.CreateSolver: ISolver;
|
||||||
begin
|
begin
|
||||||
Result := TFactor100CosmicExpansion.Create;
|
Result := TCosmicExpansion.Create(99);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCosmicExpansionExampleFactor100TestCase.TestPart2;
|
procedure TCosmicExpansionExampleFactor100TestCase.TestPart2;
|
||||||
|
|
|
@ -61,12 +61,8 @@ end;
|
||||||
{ TStepCounterMax6ExampleTestCase }
|
{ TStepCounterMax6ExampleTestCase }
|
||||||
|
|
||||||
function TStepCounterMax6ExampleTestCase.CreateSolver: ISolver;
|
function TStepCounterMax6ExampleTestCase.CreateSolver: ISolver;
|
||||||
var
|
|
||||||
solver: TStepCounter;
|
|
||||||
begin
|
begin
|
||||||
solver := TStepCounter.Create;
|
Result := TStepCounter.Create(6);
|
||||||
solver.MaxSteps := 6;
|
|
||||||
Result := solver;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TStepCounterMax6ExampleTestCase.TestPart1;
|
procedure TStepCounterMax6ExampleTestCase.TestPart1;
|
||||||
|
|
Loading…
Reference in New Issue