tests for 24

This commit is contained in:
Eric Mertens 2022-11-13 11:48:12 -08:00
parent e6f19d8ee3
commit b6e3631916

View File

@ -5,11 +5,14 @@
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <stdexcept>
#include <string>
#include <tuple>
#include <vector>
#include <doctest.h>
#include <aocpp/Startup.hpp>
#include <aocpp/Coord.hpp>
#include <aocpp/Grid.hpp>
@ -107,12 +110,12 @@ auto Part1(std::vector<Coord> const& bugs) -> std::uint32_t {
return bio;
}
auto Part2(std::vector<Coord> const& bugs) {
auto Part2(std::vector<Coord> const& bugs, int minutes) {
std::vector<Neighbor2::C3> bugs2;
for (auto const& [x,y] : bugs) {
bugs2.push_back({{x-2,y-2},0});
}
for (int i = 0; i < 200; i++) {
for (int i = 0; i < minutes; i++) {
bugs2 = Step<Neighbor2::C3, Neighbor2>(bugs2);
}
return bugs2.size();
@ -120,8 +123,20 @@ auto Part2(std::vector<Coord> const& bugs) {
} // namespace
TEST_SUITE("documented examples") {
TEST_CASE("part 1") {
std::istringstream in {"....#\n#..#.\n#..##\n..#..\n#....\n"};
REQUIRE(Part1(FindBugs(Grid::Parse(in))) == 2129920);
}
TEST_CASE("part 2") {
std::istringstream in {"....#\n#..#.\n#.?##\n..#..\n#....\n"};
REQUIRE(Part2(FindBugs(Grid::Parse(in)), 10) == 99);
}
}
auto main(int argc, char** argv) -> int {
auto const bugs = FindBugs(Grid::Parse(Startup(argc, argv)));
std::cout << "Part 1: " << Part1(bugs) << std::endl;
std::cout << "Part 2: " << Part2(std::move(bugs)) << std::endl;
std::cout << "Part 2: " << Part2(std::move(bugs), 200) << std::endl;
}