Added solution for "Day 4: Scratchcards", part 1
This commit is contained in:
@@ -48,6 +48,10 @@
|
||||
<Filename Value="UBaseTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
<Unit>
|
||||
<Filename Value="UScratchcardsTestCases.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
|
||||
@@ -3,7 +3,7 @@ program AdventOfCodeFPCUnit;
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UGearRatiosTestCases;
|
||||
Interfaces, Forms, GuiTestRunner, USolver, UBaseTestCases, UGearRatiosTestCases, UScratchcardsTestCases;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
|
||||
113
tests/UScratchcardsTestCases.pas
Normal file
113
tests/UScratchcardsTestCases.pas
Normal file
@@ -0,0 +1,113 @@
|
||||
{
|
||||
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 UScratchcardsTestCases;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, fpcunit, testregistry, USolver, UBaseTestCases, UScratchcards;
|
||||
|
||||
type
|
||||
|
||||
{ TScratchcardsBaseTestCase }
|
||||
|
||||
TScratchcardsBaseTestCase = class(TBaseTestCase)
|
||||
protected
|
||||
procedure Setup; override;
|
||||
end;
|
||||
|
||||
{ TScratchcardsFullDataTestCase }
|
||||
|
||||
TScratchcardsFullDataTestCase = class(TScratchcardsBaseTestCase)
|
||||
protected
|
||||
procedure Setup; override;
|
||||
published
|
||||
procedure TestPart1;
|
||||
procedure TestPart2;
|
||||
end;
|
||||
|
||||
{ TScratchcardsExampleTestCase }
|
||||
|
||||
TScratchcardsExampleTestCase = class(TScratchcardsBaseTestCase)
|
||||
protected
|
||||
procedure Setup; override;
|
||||
published
|
||||
procedure TestPart1;
|
||||
procedure TestPart2;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TScratchcardsBaseTestCase }
|
||||
|
||||
procedure TScratchcardsBaseTestCase.Setup;
|
||||
begin
|
||||
inherited Setup;
|
||||
FSolver := TScratchcards.Create;
|
||||
end;
|
||||
|
||||
{ TScratchcardsFullDataTestCase }
|
||||
|
||||
procedure TScratchcardsFullDataTestCase.Setup;
|
||||
begin
|
||||
inherited Setup;
|
||||
FEngine.ProcessData(FSolver);
|
||||
end;
|
||||
|
||||
procedure TScratchcardsFullDataTestCase.TestPart1;
|
||||
begin
|
||||
AssertEquals(21821, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TScratchcardsFullDataTestCase.TestPart2;
|
||||
begin
|
||||
AssertEquals(-1, FSolver.GetResultPart2);
|
||||
end;
|
||||
|
||||
{ TScratchcardsExampleTestCase }
|
||||
|
||||
procedure TScratchcardsExampleTestCase.Setup;
|
||||
begin
|
||||
inherited Setup;
|
||||
FSolver.Init;
|
||||
FSolver.ProcessDataLine('Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53');
|
||||
FSolver.ProcessDataLine('Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19');
|
||||
FSolver.ProcessDataLine('Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1');
|
||||
FSolver.ProcessDataLine('Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83');
|
||||
FSolver.ProcessDataLine('Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36');
|
||||
FSolver.ProcessDataLine('Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11');
|
||||
FSolver.Finish;
|
||||
end;
|
||||
|
||||
procedure TScratchcardsExampleTestCase.TestPart1;
|
||||
begin
|
||||
AssertEquals(13, FSolver.GetResultPart1);
|
||||
end;
|
||||
|
||||
procedure TScratchcardsExampleTestCase.TestPart2;
|
||||
begin
|
||||
AssertEquals(-1, FSolver.GetResultPart2);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
RegisterTest(TScratchcardsFullDataTestCase);
|
||||
RegisterTest(TScratchcardsExampleTestCase);
|
||||
end.
|
||||
@@ -23,3 +23,15 @@ TGearRatiosTestCase.Checked=1
|
||||
TGearRatiosTestCase.Expanded=0
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Checked=1
|
||||
TGearRatiosTestCase.TestEndOfLineNumber.Expanded=0
|
||||
TScratchcardsFullDataTestCase.Checked=1
|
||||
TScratchcardsFullDataTestCase.Expanded=1
|
||||
TScratchcardsFullDataTestCase.TestPart1.Checked=1
|
||||
TScratchcardsFullDataTestCase.TestPart1.Expanded=0
|
||||
TScratchcardsFullDataTestCase.TestPart2.Checked=1
|
||||
TScratchcardsFullDataTestCase.TestPart2.Expanded=1
|
||||
TScratchcardsExampleTestCase.Checked=1
|
||||
TScratchcardsExampleTestCase.Expanded=1
|
||||
TScratchcardsExampleTestCase.TestPart1.Checked=1
|
||||
TScratchcardsExampleTestCase.TestPart1.Expanded=0
|
||||
TScratchcardsExampleTestCase.TestPart2.Checked=1
|
||||
TScratchcardsExampleTestCase.TestPart2.Expanded=1
|
||||
|
||||
Reference in New Issue
Block a user