From 73446b2d8375c73790a5b85493df207fc37354fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Mon, 23 Dec 2024 17:53:48 +0100 Subject: [PATCH] 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. --- tests/src/TestCases.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/tests/src/TestCases.cpp b/tests/src/TestCases.cpp index 493b9b3..a8376df 100644 --- a/tests/src/TestCases.cpp +++ b/tests/src/TestCases.cpp @@ -31,6 +31,13 @@ class TestCaseBase Part2TestContext part2TestContext{ getInputPaths() }; Part1TestContext part1ExampleTestContext{ getExampleInputPaths() }; Part2TestContext part2ExampleTestContext{ getExampleInputPaths() }; + void run(std::unique_ptr&& solver, const long long int expected, const TestContext& context) + { + SolverEngine solverEngine{ context.getInputPaths() }; + solverEngine.run(*solver); + + REQUIRE(expected == context.getResult(*solver)); + } private: std::vector getInputPaths() const { @@ -43,33 +50,23 @@ class TestCaseBase } }; -template -void runTest(const long long int expected, const TestContext& context) -{ - auto solver = std::make_unique(); - SolverEngine solverEngine{ context.getInputPaths() }; - solverEngine.run(*solver); - - REQUIRE(expected == context.getResult(*solver)); -} - TEST_CASE("[HistorianHysteriaTests]") { TestCaseBase test; SECTION("FullData1") { - runTest(2176849, test.part1TestContext); + test.run(std::make_unique(), 2176849, test.part1TestContext); } SECTION("FullData2") { - runTest(23384288, test.part2TestContext); + test.run(std::make_unique(), 23384288, test.part2TestContext); } SECTION("ExampleData1") { - runTest(11, test.part1ExampleTestContext); + test.run(std::make_unique(), 11, test.part1ExampleTestContext); } SECTION("ExampleData2") { - runTest(31, test.part2ExampleTestContext); + test.run(std::make_unique(), 31, test.part2ExampleTestContext); } }