Fix bad unique pointer usage
This commit is contained in:
parent
2d3b516bbe
commit
a4f21371c3
|
@ -33,15 +33,22 @@ void Program::run()
|
||||||
runSolvers();
|
runSolvers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void runSolver(SolverEngine& solverEngine)
|
||||||
|
{
|
||||||
|
auto solver = std::make_unique<T>();
|
||||||
|
solverEngine.run(*solver);
|
||||||
|
}
|
||||||
|
|
||||||
void Program::runSolvers()
|
void Program::runSolvers()
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ getInputPaths() };
|
SolverEngine solverEngine{ getInputPaths() };
|
||||||
solverEngine.run(*std::make_unique<HistorianHysteria>());
|
runSolver<HistorianHysteria>(solverEngine);
|
||||||
solverEngine.run(*std::make_unique<RedNosedReports>());
|
runSolver<RedNosedReports>(solverEngine);
|
||||||
solverEngine.run(*std::make_unique<MullItOver>());
|
runSolver<MullItOver>(solverEngine);
|
||||||
solverEngine.run(*std::make_unique<CeresSearch>());
|
runSolver<CeresSearch>(solverEngine);
|
||||||
solverEngine.run(*std::make_unique<PrintQueue>());
|
runSolver<PrintQueue>(solverEngine);
|
||||||
solverEngine.run(*std::make_unique<GuardGallivant>());
|
runSolver<GuardGallivant>(solverEngine);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> Program::getInputPaths() const
|
std::vector<std::string> Program::getInputPaths() const
|
||||||
|
|
|
@ -13,58 +13,63 @@
|
||||||
// You should have received a copy of the GNU General Public License along with
|
// You should have received a copy of the GNU General Public License along with
|
||||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include <aocTests/Part1TestContext.h>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <aocTests/Part2TestContext.h>
|
|
||||||
|
|
||||||
#include <aoc/Solver.h>
|
#include <aoc/Solver.h>
|
||||||
#include <aoc/SolverEngine.h>
|
#include <aoc/SolverEngine.h>
|
||||||
#include <aoc/HistorianHysteria.h>
|
#include <aoc/HistorianHysteria.h>
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <aocTests/Part1TestContext.h>
|
||||||
|
#include <aocTests/Part2TestContext.h>
|
||||||
|
|
||||||
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
|
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
|
||||||
|
|
||||||
class HistorianHysteriaTests
|
class TestCaseBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Part1TestContext part1TestContext_{ getInputPaths() };
|
Part1TestContext part1TestContext{ getInputPaths() };
|
||||||
Part2TestContext part2TestContext_{ getInputPaths() };
|
Part2TestContext part2TestContext{ getInputPaths() };
|
||||||
Part1TestContext part1ExampleTestContext_{ getExampleInputPaths() };
|
Part1TestContext part1ExampleTestContext{ getExampleInputPaths() };
|
||||||
Part2TestContext part2ExampleTestContext_{ getExampleInputPaths() };
|
Part2TestContext part2ExampleTestContext{ getExampleInputPaths() };
|
||||||
|
|
||||||
void runTest(Solver &solver, const long long int expected, const TestContext &context)
|
|
||||||
{
|
|
||||||
SolverEngine solverEngine{context.getInputPaths()};
|
|
||||||
solverEngine.run(solver);
|
|
||||||
|
|
||||||
REQUIRE(expected == context.getResult(solver));
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> getInputPaths() const
|
std::vector<std::string> getInputPaths() const
|
||||||
{
|
{
|
||||||
return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
|
return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> getExampleInputPaths() const
|
std::vector<std::string> getExampleInputPaths() const
|
||||||
{
|
{
|
||||||
return std::vector<std::string>{ "data/examples", "../../../data/examples", "../../../../data/examples" };
|
return std::vector<std::string>{ "data/examples", "../../../data/examples",
|
||||||
|
"../../../../data/examples" };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE( "[HistorianHysteriaTests]" )
|
template <class T>
|
||||||
|
void runTest(const long long int expected, const TestContext& context)
|
||||||
{
|
{
|
||||||
HistorianHysteriaTests tests;
|
auto solver = std::make_unique<T>();
|
||||||
SECTION( "FullData1" ) {
|
SolverEngine solverEngine{ context.getInputPaths() };
|
||||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 2176849, tests.part1TestContext_);
|
solverEngine.run(*solver);
|
||||||
|
|
||||||
|
REQUIRE(expected == context.getResult(*solver));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[HistorianHysteriaTests]")
|
||||||
|
{
|
||||||
|
TestCaseBase test;
|
||||||
|
SECTION("FullData1")
|
||||||
|
{
|
||||||
|
runTest<HistorianHysteria>(2176849, test.part1TestContext);
|
||||||
}
|
}
|
||||||
SECTION( "FullData2" ) {
|
SECTION("FullData2")
|
||||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 23384288, tests.part2TestContext_);
|
{
|
||||||
|
runTest<HistorianHysteria>(23384288, test.part2TestContext);
|
||||||
}
|
}
|
||||||
SECTION( "ExampleData1" ) {
|
SECTION("ExampleData1")
|
||||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 11, tests.part1ExampleTestContext_);
|
{
|
||||||
|
runTest<HistorianHysteria>(11, test.part1ExampleTestContext);
|
||||||
}
|
}
|
||||||
SECTION( "ExampleData2" ) {
|
SECTION("ExampleData2")
|
||||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 31, tests.part2ExampleTestContext_);
|
{
|
||||||
|
runTest<HistorianHysteria>(31, test.part2ExampleTestContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue