-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_day_9.cpp
More file actions
88 lines (70 loc) · 1.94 KB
/
Copy pathTest_day_9.cpp
File metadata and controls
88 lines (70 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by Ryan Avery on 12/6/2022.
//
#include <gtest/gtest.h>
#include <fstream>
#include <filesystem>
#include "day_9.h"
namespace Day9 {
std::string testInput = R"(R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2)";
std::string testInput2 = R"(R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20)";
class TestDay9 : public ::testing::Test {
public:
TestDay9() : rm(testInput, 2) {}
RopeMover rm;
};
TEST_F(TestDay9, CountTailVisits_2Knots) {
ASSERT_EQ(rm.numPlacesTailVisited(), 13);
}
TEST_F(TestDay9, CountTailVisits_10Knots)
{
{
RopeMover rm10(testInput, 10, Board::Dims(10, 10));
ASSERT_EQ(rm10.numPlacesTailVisited(), 1);
}
{
RopeMover rm10(testInput2, 10, Board::Dims(100, 100));
ASSERT_EQ(rm10.numPlacesTailVisited(), 36);
}
}
TEST(Day9Answer1, CountTailVisits) {
const std::filesystem::path dir = INPUTS_DIR;
std::ifstream inFile{dir / "input_day_9.txt"};
ASSERT_TRUE(inFile);
ASSERT_TRUE(inFile.is_open());
std::ostringstream buffer;
buffer << inFile.rdbuf();
std::string str{buffer.str()};
RopeMover rm(str, 2, Board::Dims(1000,1000));
int num = rm.numPlacesTailVisited();
std::cout << "[ DAY 9 ] Num places 2-knot tail visited = " << num << std::endl;
ASSERT_EQ(num, 6037);
}
TEST(Day9Answer2, CountTailVisits_10Knots) {
const std::filesystem::path dir = INPUTS_DIR;
std::ifstream inFile{dir / "input_day_9.txt"};
ASSERT_TRUE(inFile);
ASSERT_TRUE(inFile.is_open());
std::ostringstream buffer;
buffer << inFile.rdbuf();
std::string str{buffer.str()};
RopeMover rm(str, 10, Board::Dims(1000,1000));
int num = rm.numPlacesTailVisited();
std::cout << "[ DAY 8 ] Num places 10-knot tail visited = " << num << std::endl;
ASSERT_EQ(num, 2485);
}
}