Add TestCaseBase.run() to replace the template

The template was not necessary and this now allows for use of custom constructors in the test cases.
This commit is contained in:
Stefan Müller 2024-12-23 17:53:48 +01:00
parent ff454776fa
commit 73446b2d83
1 changed files with 11 additions and 14 deletions

View File

@ -31,6 +31,13 @@ class TestCaseBase
Part2TestContext part2TestContext{ getInputPaths() };
Part1TestContext part1ExampleTestContext{ getExampleInputPaths() };
Part2TestContext part2ExampleTestContext{ getExampleInputPaths() };
void run(std::unique_ptr<Solver>&& solver, const long long int expected, const TestContext& context)
{
SolverEngine solverEngine{ context.getInputPaths() };
solverEngine.run(*solver);
REQUIRE(expected == context.getResult(*solver));
}
private:
std::vector<std::string> getInputPaths() const
{
@ -43,33 +50,23 @@ class TestCaseBase
}
};
template <class T>
void runTest(const long long int expected, const TestContext& context)
{
auto solver = std::make_unique<T>();
SolverEngine solverEngine{ context.getInputPaths() };
solverEngine.run(*solver);
REQUIRE(expected == context.getResult(*solver));
}
TEST_CASE("[HistorianHysteriaTests]")
{
TestCaseBase test;
SECTION("FullData1")
{
runTest<HistorianHysteria>(2176849, test.part1TestContext);
test.run(std::make_unique<HistorianHysteria>(), 2176849, test.part1TestContext);
}
SECTION("FullData2")
{
runTest<HistorianHysteria>(23384288, test.part2TestContext);
test.run(std::make_unique<HistorianHysteria>(), 23384288, test.part2TestContext);
}
SECTION("ExampleData1")
{
runTest<HistorianHysteria>(11, test.part1ExampleTestContext);
test.run(std::make_unique<HistorianHysteria>(), 11, test.part1ExampleTestContext);
}
SECTION("ExampleData2")
{
runTest<HistorianHysteria>(31, test.part2ExampleTestContext);
test.run(std::make_unique<HistorianHysteria>(), 31, test.part2ExampleTestContext);
}
}