Add solution for "Day 17: Chronospatial Computer", part 1
This commit is contained in:
@@ -28,6 +28,8 @@ class TestContext
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
const std::vector<std::string>& inputPaths);
|
||||
void runPart2(const std::unique_ptr<Solver<long long, long long>>&& solver, const long long expected,
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <aoc/RestroomRedoubt.hpp>
|
||||
#include <aoc/WarehouseWoes.hpp>
|
||||
#include <aoc/ReindeerMaze.hpp>
|
||||
#include <aoc/ChronospatialComputer.hpp>
|
||||
#include <aoc/LanParty.hpp>
|
||||
|
||||
#define REQUIRE_MESSAGE(cond, msg) if (!(cond)) { INFO(msg); REQUIRE(cond); }
|
||||
@@ -270,6 +271,61 @@ TEST_CASE("[ReindeerMazeTests]")
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[ChronospatialComputerTests]")
|
||||
{
|
||||
TestContext test;
|
||||
SECTION("FullData")
|
||||
{
|
||||
test.run(std::make_unique<ChronospatialComputer>(), "5,0,3,5,7,6,1,5,4", 0, test.getInputPaths());
|
||||
}
|
||||
SECTION("ExampleData")
|
||||
{
|
||||
test.run(std::make_unique<ChronospatialComputer>(), "4,6,3,5,6,3,5,2,1,0", 0, test.getExampleInputPaths());
|
||||
}
|
||||
SECTION("ExampleInstruction1")
|
||||
{
|
||||
auto solver = std::make_unique<ChronospatialComputer>();
|
||||
ChronospatialComputerState state{};
|
||||
state.registers[2] = 9;
|
||||
solver->runProgram({ 2, 6 }, state);
|
||||
REQUIRE(1 == state.registers[1]);
|
||||
}
|
||||
SECTION("ExampleInstruction2")
|
||||
{
|
||||
auto solver = std::make_unique<ChronospatialComputer>();
|
||||
ChronospatialComputerState state{};
|
||||
state.registers[0] = 10;
|
||||
solver->runProgram({ 5, 0, 5, 1, 5, 4 }, state);
|
||||
REQUIRE("0,1,2" == state.output.str());
|
||||
}
|
||||
SECTION("ExampleInstruction3")
|
||||
{
|
||||
auto solver = std::make_unique<ChronospatialComputer>();
|
||||
ChronospatialComputerState state{};
|
||||
state.registers[0] = 2024;
|
||||
solver->runProgram({ 0, 1, 5, 4, 3, 0 }, state);
|
||||
REQUIRE(0 == state.registers[0]);
|
||||
REQUIRE("4,2,5,6,7,7,7,7,3,1,0" == state.output.str());
|
||||
}
|
||||
SECTION("ExampleInstruction4")
|
||||
{
|
||||
auto solver = std::make_unique<ChronospatialComputer>();
|
||||
ChronospatialComputerState state{};
|
||||
state.registers[1] = 29;
|
||||
solver->runProgram({ 1, 7 }, state);
|
||||
REQUIRE(26 == state.registers[1]);
|
||||
}
|
||||
SECTION("ExampleInstruction5")
|
||||
{
|
||||
auto solver = std::make_unique<ChronospatialComputer>();
|
||||
ChronospatialComputerState state{};
|
||||
state.registers[1] = 2024;
|
||||
state.registers[2] = 43690;
|
||||
solver->runProgram({ 4, 0 }, state);
|
||||
REQUIRE(44354 == state.registers[1]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[LanPartyTests]")
|
||||
{
|
||||
TestContext test;
|
||||
|
||||
@@ -39,6 +39,16 @@ void TestContext::run(const std::unique_ptr<Solver<long long, std::string>>&& so
|
||||
REQUIRE(expected2 == solver->getResultPart2());
|
||||
}
|
||||
|
||||
void TestContext::run(const std::unique_ptr<Solver<std::string, long long>>&& solver, const std::string expected1,
|
||||
const long long expected2, const std::vector<std::string>& inputPaths)
|
||||
{
|
||||
SolverEngine solverEngine{ 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,
|
||||
const std::vector<std::string>& inputPaths)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user