diff --git a/tests/include/aocTests/TestContext.hpp b/tests/include/aocTests/TestContext.hpp index 93e16e2..66b4214 100644 --- a/tests/include/aocTests/TestContext.hpp +++ b/tests/include/aocTests/TestContext.hpp @@ -1,5 +1,5 @@ // Solutions to the Advent Of Code 2024. -// Copyright (C) 2024 Stefan Müller +// 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 @@ -15,6 +15,7 @@ #pragma once +#include #include #include @@ -23,8 +24,8 @@ class TestContext { public: - TestContext(std::vector inputPaths); + void run(const std::unique_ptr&& solver, const long long int expected1, + const long long int expected2, const std::vector& inputPaths); std::vector getInputPaths() const; -private: - std::vector inputPaths_; + std::vector getExampleInputPaths() const; }; diff --git a/tests/src/TestCases.cpp b/tests/src/TestCases.cpp index 4eec29b..19703ae 100644 --- a/tests/src/TestCases.cpp +++ b/tests/src/TestCases.cpp @@ -15,49 +15,20 @@ #include -#include -#include #include - #include #define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); } -class TestCaseBase -{ -public: - TestContext fullDataContext{ getInputPaths() }; - TestContext exampleDataContext{ getExampleInputPaths() }; - void run(const std::unique_ptr&& solver, const long long int expected1, - const long long int expected2, const TestContext& context) - { - SolverEngine solverEngine{ context.getInputPaths() }; - solverEngine.run(*solver); - - REQUIRE(expected1 == solver->getResultPart1()); - REQUIRE(expected2 == solver->getResultPart2()); - } -private: - std::vector getInputPaths() const - { - return std::vector{ "data", "../../../data", "../../../../data" }; - } - std::vector getExampleInputPaths() const - { - return std::vector{ "data/examples", "../../../data/examples", - "../../../../data/examples" }; - } -}; - TEST_CASE("[HistorianHysteriaTests]") { - TestCaseBase test; + TestContext test; SECTION("FullData") { - test.run(std::make_unique(), 2176849, 23384288, test.fullDataContext); + test.run(std::make_unique(), 2176849, 23384288, test.getInputPaths()); } SECTION("ExampleData") { - test.run(std::make_unique(), 11, 31, test.exampleDataContext); + test.run(std::make_unique(), 11, 31, test.getExampleInputPaths()); } } diff --git a/tests/src/TestContext.cpp b/tests/src/TestContext.cpp index 6818caf..2234036 100644 --- a/tests/src/TestContext.cpp +++ b/tests/src/TestContext.cpp @@ -15,10 +15,27 @@ #include -TestContext::TestContext(std::vector inputPaths) - : inputPaths_{ inputPaths } {} +#include + +#include + +void TestContext::run(const std::unique_ptr&& solver, const long long int expected1, + const long long int expected2, const std::vector& inputPaths) +{ + SolverEngine solverEngine{ inputPaths }; + solverEngine.run(*solver); + + REQUIRE(expected1 == solver->getResultPart1()); + REQUIRE(expected2 == solver->getResultPart2()); +} std::vector TestContext::getInputPaths() const { - return inputPaths_; + return std::vector{ "data", "../../../data", "../../../../data" }; +} + +std::vector TestContext::getExampleInputPaths() const +{ + return std::vector{ "data/examples", "../../../data/examples", + "../../../../data/examples" }; }