Added solution for "Day 3: Gear Ratios", part 1, and added test project
This commit is contained in:
15
tests/AdventOfCodeFPCUnit.fpcunit.ini
Normal file
15
tests/AdventOfCodeFPCUnit.fpcunit.ini
Normal file
@@ -0,0 +1,15 @@
|
||||
[WindowState]
|
||||
Left=664
|
||||
Top=189
|
||||
Width=575
|
||||
Height=663
|
||||
|
||||
[Tests]
|
||||
All Tests.Checked=1
|
||||
All Tests.Expanded=1
|
||||
TGearRatiosTestCase.Checked=1
|
||||
TGearRatiosTestCase.Expanded=1
|
||||
TGearRatiosTestCase.TestPuzzleExample.Checked=1
|
||||
TGearRatiosTestCase.TestPuzzleExample.Expanded=0
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Checked=1
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0
|
||||
BIN
tests/AdventOfCodeFPCUnit.ico
Normal file
BIN
tests/AdventOfCodeFPCUnit.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
84
tests/AdventOfCodeFPCUnit.lpi
Normal file
84
tests/AdventOfCodeFPCUnit.lpi
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<PathDelim Value="\"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="AdventOfCodeFPCUnit"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<RequiredPackages>
|
||||
<Item>
|
||||
<PackageName Value="fpcunittestrunner"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<PackageName Value="FCL"/>
|
||||
</Item>
|
||||
</RequiredPackages>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="AdventOfCodeFPCUnit.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="UGearRatiosTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="..\USolver.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<PathDelim Value="\"/>
|
||||
<Target>
|
||||
<Filename Value="AdventOfCodeFPCUnit"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="..\solvers;.."/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf3"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
||||
15
tests/AdventOfCodeFPCUnit.lpr
Normal file
15
tests/AdventOfCodeFPCUnit.lpr
Normal file
@@ -0,0 +1,15 @@
|
||||
program AdventOfCodeFPCUnit;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Interfaces, Forms, GuiTestRunner, UGearRatiosTestCases, USolver;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TGuiTestRunner, TestRunner);
|
||||
Application.Run;
|
||||
end.
|
||||
|
||||
83
tests/UGearRatiosTestCases.pas
Normal file
83
tests/UGearRatiosTestCases.pas
Normal file
@@ -0,0 +1,83 @@
|
||||
{
|
||||
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 UGearRatiosTestCases;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, UGearRatios;
|
||||
|
||||
type
|
||||
|
||||
{ TGearRatiosTestCase }
|
||||
|
||||
TGearRatiosTestCase = class(TTestCase)
|
||||
protected
|
||||
FSolver: TGearRatios;
|
||||
procedure Setup; override;
|
||||
procedure TearDown; override;
|
||||
published
|
||||
procedure TestPuzzleExample;
|
||||
procedure TestEndOfLineNumber;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TGearRatiosTestCase }
|
||||
|
||||
procedure TGearRatiosTestCase.Setup;
|
||||
begin
|
||||
FSolver := TGearRatios.Create;
|
||||
end;
|
||||
|
||||
procedure TGearRatiosTestCase.TearDown;
|
||||
begin
|
||||
FSolver.Free;
|
||||
end;
|
||||
|
||||
procedure TGearRatiosTestCase.TestPuzzleExample;
|
||||
begin
|
||||
FSolver.Init;
|
||||
FSolver.ProcessDataLine('467..114..');
|
||||
FSolver.ProcessDataLine('...*......');
|
||||
FSolver.ProcessDataLine('..35..633.');
|
||||
FSolver.ProcessDataLine('......#...');
|
||||
FSolver.ProcessDataLine('617*......');
|
||||
FSolver.ProcessDataLine('.....+.58.');
|
||||
FSolver.ProcessDataLine('..592.....');
|
||||
FSolver.ProcessDataLine('......755.');
|
||||
FSolver.ProcessDataLine('...$.*....');
|
||||
FSolver.ProcessDataLine('.664.598..');
|
||||
FSolver.Finish;
|
||||
AssertEquals('Result of part 1 calculation incorrect.', 4361, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TGearRatiosTestCase.TestEndOfLineNumber;
|
||||
begin
|
||||
FSolver.Init;
|
||||
FSolver.ProcessDataLine('...$541');
|
||||
FSolver.Finish;
|
||||
AssertEquals('Result of part 1 calculation incorrect.', 541, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterTest(TGearRatiosTestCase);
|
||||
end.
|
||||
Reference in New Issue
Block a user