Skip to content

Commit ccd944e

Browse files
committed
Added actual puzzles to tests
1 parent 6c049ea commit ccd944e

File tree

5 files changed

+99
-37
lines changed

5 files changed

+99
-37
lines changed

.github/workflows/build_test.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,3 @@ jobs:
3232
echo "Unit tests failed"
3333
exit 1
3434
fi
35-
- name: Run Day 1 Solution
36-
run: ./build/solutions/day_1 solutions/data/day_1.txt
37-
- name: Run Day 2 Solution
38-
run: ./build/solutions/day_2 solutions/data/day_2.txt
39-
- name: Run Day 3 Solution
40-
run: ./build/solutions/day_3 solutions/data/day_3.txt
41-
- name: Run Day 4 Solution
42-
run: ./build/solutions/day_3 solutions/data/day_4.txt

tests/test_day_1.cxx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#error "ADVENT_OF_CODE_DATA is not defined!"
99
#endif
1010

11-
TEST(TestAOC, TestDay1pt1) {
11+
TEST(TestAOC, TestDay1pt1_example) {
1212
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_1_1.txt";
1313

1414
const std::vector<int> diffs{AdventOfCode24::Day1::get_differences(input_file)};
@@ -17,11 +17,29 @@ TEST(TestAOC, TestDay1pt1) {
1717
ASSERT_EQ(diff_total, 11);
1818
}
1919

20-
TEST(TestAOC, TestDay1pt2) {
20+
TEST(TestAOC, TestDay1pt1) {
21+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_1.txt";
22+
23+
const std::vector<int> diffs{AdventOfCode24::Day1::get_differences(input_file)};
24+
const int diff_total = std::accumulate(diffs.begin(), diffs.end(), 0);
25+
26+
ASSERT_EQ(diff_total, 1722302);
27+
}
28+
29+
TEST(TestAOC, TestDay1pt2_example) {
2130
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_1_1.txt";
2231

2332
const std::vector<int> diffs{AdventOfCode24::Day1::get_similarity_scores(input_file)};
2433
const int score_total = std::accumulate(diffs.begin(), diffs.end(), 0);
2534

2635
ASSERT_EQ(score_total, 31);
2736
}
37+
38+
TEST(TestAOC, TestDay1pt2) {
39+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_1.txt";
40+
41+
const std::vector<int> diffs{AdventOfCode24::Day1::get_similarity_scores(input_file)};
42+
const int score_total = std::accumulate(diffs.begin(), diffs.end(), 0);
43+
44+
ASSERT_EQ(score_total, 20373490);
45+
}

tests/test_day_2.cxx

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,6 @@ TEST(TestAOC, TestDay2pt1_valid) {
4949
ASSERT_TRUE(layer_safety);
5050
}
5151

52-
TEST(TestAOC, TestDay2pt1) {
53-
const std::string line("1 2 4 7 3 7 2 1");
54-
std::istringstream sstr;
55-
sstr.str(line);
56-
57-
const std::vector<int> values{read_line(sstr)};
58-
const bool layer_safety = AdventOfCode24::Day2::level_trend_is_valid(values, false);
59-
60-
ASSERT_FALSE(layer_safety);
61-
}
62-
6352
TEST(TestAOC, TestDay2pt1_file1) {
6453
spdlog::set_level(spdlog::level::debug);
6554
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_2_1.txt";
@@ -73,6 +62,19 @@ TEST(TestAOC, TestDay2pt1_file1) {
7362
ASSERT_EQ(n_safe, 2);
7463
}
7564

65+
TEST(TestAOC, TestDay2pt1) {
66+
spdlog::set_level(spdlog::level::debug);
67+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_2.txt";
68+
69+
const std::vector<bool> layer_safety = AdventOfCode24::Day2::check_reactor_safety(input_file, false);
70+
71+
ASSERT_EQ(layer_safety.size(), 1000);
72+
73+
const int n_safe = std::count_if(layer_safety.begin(), layer_safety.end(), [](bool x){return x;});
74+
75+
ASSERT_EQ(n_safe, 402);
76+
}
77+
7678
TEST(TestAOC, TestDay2pt2_file1) {
7779
spdlog::set_level(spdlog::level::debug);
7880

@@ -118,4 +120,29 @@ TEST(TestAOC, TestDay2pt2_file2) {
118120

119121
index++;
120122
}
123+
}
124+
125+
TEST(TestAOC, TestDay2pt2) {
126+
spdlog::set_level(spdlog::level::debug);
127+
128+
std::vector<bool> expected{true, false, false, true, true, true};
129+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_2.txt";
130+
int index{0};
131+
int counter{0};
132+
133+
std::ifstream read_in(input_file, std::ios::in);
134+
std::string line;
135+
136+
while (std::getline(read_in, line)) {
137+
spdlog::info("Running Line " + std::to_string(index));
138+
std::istringstream stream(line, std::ios::in);
139+
140+
const std::vector<int> values{read_line(stream)};
141+
const bool layer_safety = AdventOfCode24::Day2::level_trend_is_valid(values, true);
142+
143+
if(layer_safety) counter++;
144+
index++;
145+
}
146+
147+
ASSERT_EQ(counter, 455);
121148
}

tests/test_day_3.cxx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ TEST(TestAOC, TestDay3pt1_line_parse) {
2424
ASSERT_EQ(parsed[0].second, 5);
2525
}
2626

27-
TEST(TestAOC, TestDay3pt1) {
27+
TEST(TestAOC, TestDay3pt1_example) {
2828
spdlog::set_level(spdlog::level::debug);
2929
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_3_1.txt";
3030
const std::vector<int> line_totals{AdventOfCode24::Day3::calculate_file_lines(input_file, false)};
@@ -35,7 +35,7 @@ TEST(TestAOC, TestDay3pt1) {
3535
ASSERT_EQ(overall_total, 161);
3636
}
3737

38-
TEST(TestAOC, TestDay3pt2) {
38+
TEST(TestAOC, TestDay3pt2_example) {
3939
spdlog::set_level(spdlog::level::debug);
4040
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_3_2.txt";
4141
const std::vector<int> line_totals{AdventOfCode24::Day3::calculate_file_lines(input_file, true)};
@@ -46,6 +46,26 @@ TEST(TestAOC, TestDay3pt2) {
4646
ASSERT_EQ(overall_total, 48);
4747
}
4848

49+
TEST(TestAOC, TestDay3pt1) {
50+
spdlog::set_level(spdlog::level::debug);
51+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_3.txt";
52+
const std::vector<int> line_totals{AdventOfCode24::Day3::calculate_file_lines(input_file, false)};
53+
54+
const int overall_total = std::accumulate(line_totals.begin(), line_totals.end(), 0);
55+
56+
ASSERT_EQ(overall_total, 187833789);
57+
}
58+
59+
TEST(TestAOC, TestDay3pt2) {
60+
spdlog::set_level(spdlog::level::debug);
61+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_3.txt";
62+
const std::vector<int> line_totals{AdventOfCode24::Day3::calculate_file_lines(input_file, true)};
63+
64+
const int overall_total = std::accumulate(line_totals.begin(), line_totals.end(), 0);
65+
66+
ASSERT_EQ(overall_total, 94455185);
67+
}
68+
4969
TEST(TestAOC, TestDay3pt2_scenario_1) {
5070
spdlog::set_level(spdlog::level::debug);
5171
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_3_3.txt";

tests/test_day_4.cxx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ using namespace AdventOfCode24::Day4;
1111
#error "ADVENT_OF_CODE_DATA is not defined!"
1212
#endif
1313

14-
TEST(TestAOC, TestDay4pt1_block_parse) {
15-
spdlog::set_level(spdlog::level::debug);
16-
const std::string word{"XMAS"};
17-
const std::deque<std::string> block{"XMASFVX.", "MMDNTMY.", "AIAWAZV.", "STCSAMX.", "ZNAAALA.", "QMTMMMM.", "XIYXJFX.", "......."};
18-
const int n_matches{wordsearch_matches(word, block, 0)};
19-
20-
ASSERT_EQ(n_matches, 8);
21-
}
22-
23-
TEST(TestAOC, TestDay4pt1_1) {
14+
TEST(TestAOC, TestDay4pt1_example) {
2415
spdlog::set_level(spdlog::level::debug);
2516
const std::string word{"XMAS"};
2617
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_4_1.txt";
@@ -29,21 +20,35 @@ TEST(TestAOC, TestDay4pt1_1) {
2920
ASSERT_EQ(word_count, 18);
3021
}
3122

32-
TEST(TestAOC, TestDay4pt2) {
33-
spdlog::set_level(spdlog::level::debug);
23+
TEST(TestAOC, TestDay4pt2_example_1) {
3424
const std::string word{"MAS"};
3525
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_4_1.txt";
3626
const int word_count{AdventOfCode24::Day4::count_matches_in_file(input_file, word, false)};
3727

3828
ASSERT_EQ(word_count, 9);
3929
}
4030

41-
TEST(TestAOC, TestDay4pt1_2) {
42-
spdlog::set_level(spdlog::level::debug);
31+
TEST(TestAOC, TestDay4pt1_example_2) {
4332
const std::string word{"XMAS"};
4433
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / "day_4_2.txt";
4534
const int word_count{AdventOfCode24::Day4::count_matches_in_file(input_file, word, true)};
4635

4736
ASSERT_EQ(word_count, 18);
4837
}
4938

39+
TEST(TestAOC, TestDay4pt1) {
40+
const std::string word{"XMAS"};
41+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_4.txt";
42+
const int word_count{AdventOfCode24::Day4::count_matches_in_file(input_file, word, true)};
43+
44+
ASSERT_EQ(word_count, 2654);
45+
}
46+
47+
TEST(TestAOC, TestDay4pt2) {
48+
const std::string word{"MAS"};
49+
const std::filesystem::path input_file = std::filesystem::path(ADVENT_OF_CODE_DATA) / ".." / ".." / "solutions" / "data" / "day_4.txt";
50+
const int word_count{AdventOfCode24::Day4::count_matches_in_file(input_file, word, false)};
51+
52+
ASSERT_EQ(word_count, 1990);
53+
}
54+

0 commit comments

Comments
 (0)