Fix bad unique pointer usage
This commit is contained in:
parent
2d3b516bbe
commit
a4f21371c3
|
@ -33,15 +33,22 @@ void Program::run()
|
|||
runSolvers();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void runSolver(SolverEngine& solverEngine)
|
||||
{
|
||||
auto solver = std::make_unique<T>();
|
||||
solverEngine.run(*solver);
|
||||
}
|
||||
|
||||
void Program::runSolvers()
|
||||
{
|
||||
SolverEngine solverEngine{ getInputPaths() };
|
||||
solverEngine.run(*std::make_unique<HistorianHysteria>());
|
||||
solverEngine.run(*std::make_unique<RedNosedReports>());
|
||||
solverEngine.run(*std::make_unique<MullItOver>());
|
||||
solverEngine.run(*std::make_unique<CeresSearch>());
|
||||
solverEngine.run(*std::make_unique<PrintQueue>());
|
||||
solverEngine.run(*std::make_unique<GuardGallivant>());
|
||||
runSolver<HistorianHysteria>(solverEngine);
|
||||
runSolver<RedNosedReports>(solverEngine);
|
||||
runSolver<MullItOver>(solverEngine);
|
||||
runSolver<CeresSearch>(solverEngine);
|
||||
runSolver<PrintQueue>(solverEngine);
|
||||
runSolver<GuardGallivant>(solverEngine);
|
||||
}
|
||||
|
||||
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
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <aocTests/Part1TestContext.h>
|
||||
#include <aocTests/Part2TestContext.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <aoc/Solver.h>
|
||||
#include <aoc/SolverEngine.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); }
|
||||
|
||||
class HistorianHysteriaTests
|
||||
class TestCaseBase
|
||||
{
|
||||
public:
|
||||
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);
|
||||
|
||||
REQUIRE(expected == context.getResult(solver));
|
||||
}
|
||||
|
||||
Part1TestContext part1TestContext{ getInputPaths() };
|
||||
Part2TestContext part2TestContext{ getInputPaths() };
|
||||
Part1TestContext part1ExampleTestContext{ getExampleInputPaths() };
|
||||
Part2TestContext part2ExampleTestContext{ getExampleInputPaths() };
|
||||
private:
|
||||
std::vector<std::string> getInputPaths() const
|
||||
{
|
||||
return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
|
||||
}
|
||||
|
||||
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;
|
||||
SECTION( "FullData1" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 2176849, tests.part1TestContext_);
|
||||
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);
|
||||
}
|
||||
SECTION( "FullData2" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 23384288, tests.part2TestContext_);
|
||||
SECTION("FullData2")
|
||||
{
|
||||
runTest<HistorianHysteria>(23384288, test.part2TestContext);
|
||||
}
|
||||
SECTION( "ExampleData1" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 11, tests.part1ExampleTestContext_);
|
||||
SECTION("ExampleData1")
|
||||
{
|
||||
runTest<HistorianHysteria>(11, test.part1ExampleTestContext);
|
||||
}
|
||||
SECTION( "ExampleData2" ) {
|
||||
tests.runTest(*std::make_unique<HistorianHysteria>(), 31, tests.part2ExampleTestContext_);
|
||||
SECTION("ExampleData2")
|
||||
{
|
||||
runTest<HistorianHysteria>(31, test.part2ExampleTestContext);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue