Update unit tests with contexts
This commit is contained in:
parent
f8567033f4
commit
5f08565799
|
@ -0,0 +1,25 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "Part1TestContext.h"
|
||||
|
||||
Part1TestContext::Part1TestContext(std::vector<std::string> inputPaths)
|
||||
: TestContext{ inputPaths } {}
|
||||
|
||||
long long int Part1TestContext::getResult(Solver& solver) const
|
||||
{
|
||||
return solver.getResultPart1();
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TestContext.h"
|
||||
|
||||
class Part1TestContext :
|
||||
public TestContext
|
||||
{
|
||||
public:
|
||||
Part1TestContext(std::vector<std::string> inputPaths);
|
||||
virtual long long int getResult(Solver& solver) const override;
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "Part2TestContext.h"
|
||||
|
||||
Part2TestContext::Part2TestContext(std::vector<std::string> inputPaths)
|
||||
: TestContext{ inputPaths } {}
|
||||
|
||||
long long int Part2TestContext::getResult(Solver& solver) const
|
||||
{
|
||||
return solver.getResultPart2();
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TestContext.h"
|
||||
|
||||
class Part2TestContext :
|
||||
public TestContext
|
||||
{
|
||||
public:
|
||||
Part2TestContext(std::vector<std::string> inputPaths);
|
||||
virtual long long int getResult(Solver& solver) const override;
|
||||
};
|
|
@ -0,0 +1,25 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#include "pch.h"
|
||||
#include "TestContext.h"
|
||||
|
||||
TestContext::TestContext(std::vector<std::string> inputPaths)
|
||||
: inputPaths_{ inputPaths } {}
|
||||
|
||||
std::vector<std::string> TestContext::getInputPaths() const
|
||||
{
|
||||
return inputPaths_;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 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/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Solver.h>
|
||||
|
||||
class TestContext
|
||||
{
|
||||
public:
|
||||
TestContext(std::vector<std::string> inputPaths);
|
||||
virtual ~TestContext() {};
|
||||
std::vector<std::string> getInputPaths() const;
|
||||
virtual long long int getResult(Solver& solver) const = 0;
|
||||
private:
|
||||
std::vector<std::string> inputPaths_;
|
||||
};
|
|
@ -16,6 +16,8 @@
|
|||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
|
||||
#include "Part1TestContext.h"
|
||||
#include "Part2TestContext.h"
|
||||
#include "../Demo.h"
|
||||
#include "../Solver.h"
|
||||
#include "../SolverEngine.h"
|
||||
|
@ -29,37 +31,37 @@ namespace UnitTests
|
|||
public:
|
||||
TEST_METHOD(FullData1)
|
||||
{
|
||||
SolverEngine solverEngine{ getInputPaths() };
|
||||
std::unique_ptr<Solver> solver{ std::make_unique<Demo>() };
|
||||
solverEngine.run(*solver);
|
||||
assertAreEqual(66, solver->getResultPart1());
|
||||
runTest(*std::make_unique<Demo>(), 66, part1TestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(FullData2)
|
||||
{
|
||||
SolverEngine solverEngine{ getInputPaths() };
|
||||
std::unique_ptr<Solver> solver = std::make_unique<Demo>();
|
||||
solverEngine.run(*solver);
|
||||
assertAreEqual(39916800, solver->getResultPart2());
|
||||
runTest(*std::make_unique<Demo>(), 39916800, part2TestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(ExampleData1)
|
||||
{
|
||||
SolverEngine solverEngine{ getExampleInputPaths() };
|
||||
std::unique_ptr<Solver> solver = std::make_unique<Demo>();
|
||||
solverEngine.run(*solver);
|
||||
assertAreEqual(10, solver->getResultPart1());
|
||||
runTest(*std::make_unique<Demo>(), 10, part1ExampleTestContext_);
|
||||
}
|
||||
|
||||
TEST_METHOD(ExampleData2)
|
||||
{
|
||||
SolverEngine solverEngine{ getExampleInputPaths() };
|
||||
std::unique_ptr<Solver> solver = std::make_unique<Demo>();
|
||||
solverEngine.run(*solver);
|
||||
assertAreEqual(24, solver->getResultPart2());
|
||||
runTest(*std::make_unique<Demo>(), 24, part2ExampleTestContext_);
|
||||
}
|
||||
|
||||
private:
|
||||
Part1TestContext part1TestContext_{ getInputPaths() };
|
||||
Part2TestContext part2TestContext_{ getInputPaths() };
|
||||
Part1TestContext part1ExampleTestContext_{ getExampleInputPaths() };
|
||||
Part2TestContext part2ExampleTestContext_{ getExampleInputPaths() };
|
||||
|
||||
void runTest(Solver& solver, const long long int expected, const TestContext& context)
|
||||
{
|
||||
SolverEngine solverEngine{ context.getInputPaths() };
|
||||
solverEngine.run(solver);
|
||||
assertAreEqual(expected, context.getResult(solver));
|
||||
}
|
||||
|
||||
std::vector<std::string> getInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "../../data", "../../../../data" };
|
||||
|
|
|
@ -159,16 +159,22 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Part1TestContext.cpp" />
|
||||
<ClCompile Include="Part2TestContext.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TestContext.cpp" />
|
||||
<ClCompile Include="UnitTests.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Part1TestContext.h" />
|
||||
<ClInclude Include="Part2TestContext.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="TestContext.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdventOfCode2024.vcxproj">
|
||||
|
|
|
@ -21,10 +21,28 @@
|
|||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TestContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Part1TestContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Part2TestContext.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="TestContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Part1TestContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Part2TestContext.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue