76 lines
3.1 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 run(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected1, const int64_t expected2,
const std::vector<std::string>& inputPaths);
void run(std::unique_ptr<Solver<int64_t, std::string>>&& solver, const int64_t expected1,
const std::string& expected2, const std::vector<std::string>& inputPaths);
void run(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected1,
const int64_t expected2, const std::vector<std::string>& inputPaths);
void runPart1(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths);
void runPart1(std::unique_ptr<Solver<std::string, int64_t>>&& solver, const std::string& expected,
const std::vector<std::string>& inputPaths);
void runPart2(std::unique_ptr<Solver<int64_t, int64_t>>&& solver, const int64_t expected,
const std::vector<std::string>& inputPaths);
std::vector<std::string> getInputPaths() 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());
}
};