Update TestContext to simply provide a generic test run and the input path methods
This commit is contained in:
parent
c85cffb992
commit
896d41c561
|
@ -1,5 +1,5 @@
|
|||
// 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
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
|
@ -15,6 +15,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -23,8 +24,8 @@
|
|||
class TestContext
|
||||
{
|
||||
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;
|
||||
private:
|
||||
std::vector<std::string> inputPaths_;
|
||||
std::vector<std::string> getExampleInputPaths() const;
|
||||
};
|
||||
|
|
|
@ -15,49 +15,20 @@
|
|||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <aoc/Solver.hpp>
|
||||
#include <aoc/SolverEngine.hpp>
|
||||
#include <aoc/HistorianHysteria.hpp>
|
||||
|
||||
#include <aocTests/TestContext.hpp>
|
||||
|
||||
#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]")
|
||||
{
|
||||
TestCaseBase test;
|
||||
TestContext test;
|
||||
SECTION("FullData")
|
||||
{
|
||||
test.run(std::make_unique<HistorianHysteria>(), 2176849, 23384288, test.fullDataContext);
|
||||
test.run(std::make_unique<HistorianHysteria>(), 2176849, 23384288, test.getInputPaths());
|
||||
}
|
||||
SECTION("ExampleData")
|
||||
{
|
||||
test.run(std::make_unique<HistorianHysteria>(), 11, 31, test.exampleDataContext);
|
||||
test.run(std::make_unique<HistorianHysteria>(), 11, 31, test.getExampleInputPaths());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,27 @@
|
|||
|
||||
#include <aocTests/TestContext.hpp>
|
||||
|
||||
TestContext::TestContext(std::vector<std::string> inputPaths)
|
||||
: inputPaths_{ inputPaths } {}
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#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
|
||||
{
|
||||
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" };
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue