Add TestContext::runGeneric() template function (and variants)
This commit is contained in:
parent
4b95a250bd
commit
97b61836d8
@ -19,23 +19,57 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
#include <aoc/framework/Solver.hpp>
|
#include <aoc/framework/Solver.hpp>
|
||||||
|
#include <aoc/framework/SolverEngine.hpp>
|
||||||
|
|
||||||
class TestContext
|
class TestContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void run(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected1,
|
void run(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected1,
|
||||||
const long long expected2, const std::vector<std::string>& inputPaths);
|
const long long& expected2, const std::vector<std::string>& inputPaths);
|
||||||
void run(const std::unique_ptr<Solver<long long, std::string>>&& solver, const long long expected1,
|
void run(std::unique_ptr<Solver<long long, std::string>>&& solver, const long long& expected1,
|
||||||
const std::string expected2, const std::vector<std::string>& inputPaths);
|
const std::string& expected2, const std::vector<std::string>& inputPaths);
|
||||||
void run(const std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string expected1,
|
void run(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected1,
|
||||||
const long long expected2, const std::vector<std::string>& inputPaths);
|
const long long& expected2, const std::vector<std::string>& inputPaths);
|
||||||
void runPart1(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
void runPart1(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
|
||||||
const std::vector<std::string>& inputPaths);
|
const std::vector<std::string>& inputPaths);
|
||||||
void runPart1(const std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string expected,
|
void runPart1(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected,
|
||||||
const std::vector<std::string>& inputPaths);
|
const std::vector<std::string>& inputPaths);
|
||||||
void runPart2(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
void runPart2(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
|
||||||
const std::vector<std::string>& inputPaths);
|
const std::vector<std::string>& inputPaths);
|
||||||
std::vector<std::string> getInputPaths() const;
|
std::vector<std::string> getInputPaths() const;
|
||||||
std::vector<std::string> getExampleInputPaths() const;
|
std::vector<std::string> getExampleInputPaths() const;
|
||||||
|
private:
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
void runGeneric(const std::unique_ptr<Solver<T1, T2>>&& solver, const T1& expected1, const T2& expected2,
|
||||||
|
const std::vector<std::string>& inputPaths)
|
||||||
|
{
|
||||||
|
SolverEngine solverEngine{ inputPaths };
|
||||||
|
solverEngine.run(*solver);
|
||||||
|
|
||||||
|
REQUIRE(expected1 == solver->getResultPart1());
|
||||||
|
REQUIRE(expected2 == solver->getResultPart2());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
void runPart1Generic(const std::unique_ptr<Solver<T1, T2>>&& solver, const T1& expected,
|
||||||
|
const std::vector<std::string>& inputPaths)
|
||||||
|
{
|
||||||
|
SolverEngine solverEngine{ inputPaths };
|
||||||
|
solverEngine.run(*solver);
|
||||||
|
|
||||||
|
REQUIRE(expected == solver->getResultPart1());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
void runPart2Generic(const std::unique_ptr<Solver<T1, T2>>&& solver, const T2& expected,
|
||||||
|
const std::vector<std::string>& inputPaths)
|
||||||
|
{
|
||||||
|
SolverEngine solverEngine{ inputPaths };
|
||||||
|
solverEngine.run(*solver);
|
||||||
|
|
||||||
|
REQUIRE(expected == solver->getResultPart2());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -15,65 +15,40 @@
|
|||||||
|
|
||||||
#include <aocTests/TestContext.hpp>
|
#include <aocTests/TestContext.hpp>
|
||||||
|
|
||||||
#include <catch2/catch_test_macros.hpp>
|
void TestContext::run(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected1,
|
||||||
|
const long long& expected2, const std::vector<std::string>& inputPaths)
|
||||||
#include <aoc/framework/SolverEngine.hpp>
|
|
||||||
|
|
||||||
void TestContext::run(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected1,
|
|
||||||
const long long expected2, const std::vector<std::string>& inputPaths)
|
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runGeneric(std::move(solver), expected1, expected2, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected1 == solver->getResultPart1());
|
|
||||||
REQUIRE(expected2 == solver->getResultPart2());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::run(const std::unique_ptr<Solver<long long, std::string>>&& solver, const long long expected1,
|
void TestContext::run(std::unique_ptr<Solver<long long, std::string>>&& solver, const long long& expected1,
|
||||||
const std::string expected2, const std::vector<std::string>& inputPaths)
|
const std::string& expected2, const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runGeneric(std::move(solver), expected1, expected2, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected1 == solver->getResultPart1());
|
|
||||||
REQUIRE(expected2 == solver->getResultPart2());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::run(const std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string expected1,
|
void TestContext::run(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected1,
|
||||||
const long long expected2, const std::vector<std::string>& inputPaths)
|
const long long& expected2, const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runGeneric(std::move(solver), expected1, expected2, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected1 == solver->getResultPart1());
|
|
||||||
REQUIRE(expected2 == solver->getResultPart2());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::runPart1(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
void TestContext::runPart1(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
|
||||||
const std::vector<std::string>& inputPaths)
|
const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runPart1Generic(std::move(solver), expected, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected == solver->getResultPart1());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::runPart1(const std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string expected,
|
void TestContext::runPart1(std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string& expected,
|
||||||
const std::vector<std::string>& inputPaths)
|
const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runPart1Generic(std::move(solver), expected, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected == solver->getResultPart1());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestContext::runPart2(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
void TestContext::runPart2(std::unique_ptr<Solver<long long, long long>>&& solver, const long long& expected,
|
||||||
const std::vector<std::string>& inputPaths)
|
const std::vector<std::string>& inputPaths)
|
||||||
{
|
{
|
||||||
SolverEngine solverEngine{ inputPaths };
|
runPart2Generic(std::move(solver), expected, inputPaths);
|
||||||
solverEngine.run(*solver);
|
|
||||||
|
|
||||||
REQUIRE(expected == solver->getResultPart2());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> TestContext::getInputPaths() const
|
std::vector<std::string> TestContext::getInputPaths() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user