From b6e36319166ef8902400e64baf5c7b9be29b4c4e Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Sun, 13 Nov 2022 11:48:12 -0800 Subject: [PATCH] tests for 24 --- 2019/24.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/2019/24.cpp b/2019/24.cpp index 21494cb..2640b7d 100644 --- a/2019/24.cpp +++ b/2019/24.cpp @@ -5,11 +5,14 @@ #include #include #include +#include #include #include #include #include +#include + #include #include #include @@ -107,12 +110,12 @@ auto Part1(std::vector const& bugs) -> std::uint32_t { return bio; } -auto Part2(std::vector const& bugs) { +auto Part2(std::vector const& bugs, int minutes) { std::vector 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(bugs2); } return bugs2.size(); @@ -120,8 +123,20 @@ auto Part2(std::vector 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; }