78 lines
3.2 KiB
C++
78 lines
3.2 KiB
C++
// Solutions to the Advent Of Code 2024.
|
|
// Copyright (C) 2024-2025 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
|
|
// Foundation, either version 3 of the License, or (at your option) any later
|
|
// version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful, but WITHOUT
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License along with
|
|
// this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <aoc/framework/Solver.hpp>
|
|
#include <aoc/framework/SolverEngine.hpp>
|
|
|
|
class TestContext
|
|
{
|
|
public:
|
|
void runFull(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected1, const int64_t expected2);
|
|
void runFull(std::unique_ptr<Solver<int64_t, std::string>>&& solver, const int64_t expected1,
|
|
const std::string& expected2);
|
|
void runFull(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected1,
|
|
const int64_t expected2);
|
|
void runExample(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected1,
|
|
const int64_t expected2);
|
|
void runExample(std::unique_ptr<Solver<int64_t, std::string>>&& solver, const int64_t expected1,
|
|
const std::string& expected2);
|
|
void runExamplePart1(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected);
|
|
void runExamplePart1(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected);
|
|
void runExamplePart2(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected);
|
|
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());
|
|
}
|
|
|
|
static const inline std::vector<std::string> inputPaths_{ "data", "../../../data", "../../../../data" };
|
|
static const inline std::vector<std::string> exampleInputPaths_{ "data/examples", "../../../data/examples",
|
|
"../../../../data/examples" };
|
|
};
|