Update TestContext to simply provide a generic test run and the input path methods

This commit is contained in:
Stefan Müller 2024-12-23 18:26:03 +01:00
parent c85cffb992
commit 896d41c561
3 changed files with 28 additions and 39 deletions

View File

@ -1,5 +1,5 @@
// Solutions to the Advent Of Code 2024. // Solutions to the Advent Of Code 2024.
// Copyright (C) 2024 Stefan Müller // Copyright (C) 2024 Stefan Müller
// //
// This program is free software: you can redistribute it and/or modify it under // 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 // the terms of the GNU General Public License as published by the Free Software
@ -15,6 +15,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -23,8 +24,8 @@
class TestContext class TestContext
{ {
public: public:
TestContext(std::vector<std::string> inputPaths); void run(const std::unique_ptr<Solver>&& solver, const long long int expected1,
const long long int expected2, const std::vector<std::string>& inputPaths);
std::vector<std::string> getInputPaths() const; std::vector<std::string> getInputPaths() const;
private: std::vector<std::string> getExampleInputPaths() const;
std::vector<std::string> inputPaths_;
}; };

View File

@ -15,49 +15,20 @@
#include <catch2/catch_test_macros.hpp> #include <catch2/catch_test_macros.hpp>
#include <aoc/Solver.hpp>
#include <aoc/SolverEngine.hpp>
#include <aoc/HistorianHysteria.hpp> #include <aoc/HistorianHysteria.hpp>
#include <aocTests/TestContext.hpp> #include <aocTests/TestContext.hpp>
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); } #define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
class TestCaseBase
{
public:
TestContext fullDataContext{ getInputPaths() };
TestContext exampleDataContext{ getExampleInputPaths() };
void run(const std::unique_ptr<Solver>&& solver, const long long int expected1,
const long long int expected2, const TestContext& context)
{
SolverEngine solverEngine{ context.getInputPaths() };
solverEngine.run(*solver);
REQUIRE(expected1 == solver->getResultPart1());
REQUIRE(expected2 == solver->getResultPart2());
}
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" };
}
};
TEST_CASE("[HistorianHysteriaTests]") TEST_CASE("[HistorianHysteriaTests]")
{ {
TestCaseBase test; TestContext test;
SECTION("FullData") SECTION("FullData")
{ {
test.run(std::make_unique<HistorianHysteria>(), 2176849, 23384288, test.fullDataContext); test.run(std::make_unique<HistorianHysteria>(), 2176849, 23384288, test.getInputPaths());
} }
SECTION("ExampleData") SECTION("ExampleData")
{ {
test.run(std::make_unique<HistorianHysteria>(), 11, 31, test.exampleDataContext); test.run(std::make_unique<HistorianHysteria>(), 11, 31, test.getExampleInputPaths());
} }
} }

View File

@ -15,10 +15,27 @@
#include <aocTests/TestContext.hpp> #include <aocTests/TestContext.hpp>
TestContext::TestContext(std::vector<std::string> inputPaths) #include <catch2/catch_test_macros.hpp>
: inputPaths_{ inputPaths } {}
#include <aoc/SolverEngine.hpp>
void TestContext::run(const std::unique_ptr<Solver>&& solver, const long long int expected1,
const long long int expected2, const std::vector<std::string>& inputPaths)
{
SolverEngine solverEngine{ inputPaths };
solverEngine.run(*solver);
REQUIRE(expected1 == solver->getResultPart1());
REQUIRE(expected2 == solver->getResultPart2());
}
std::vector<std::string> TestContext::getInputPaths() const std::vector<std::string> TestContext::getInputPaths() const
{ {
return inputPaths_; return std::vector<std::string>{ "data", "../../../data", "../../../../data" };
}
std::vector<std::string> TestContext::getExampleInputPaths() const
{
return std::vector<std::string>{ "data/examples", "../../../data/examples",
"../../../../data/examples" };
} }