-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDayThreeTests.cpp
82 lines (69 loc) · 3.1 KB
/
DayThreeTests.cpp
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
//
// Created by Aidan Nagorcka-Smith on 30/12/2022.
//
#include <gtest/gtest.h>
#include <nanobench.h>
#include "DayThree.h"
#include "DayThreeParser.h"
namespace AdventOfCode::DayThree {
TEST(DayThree, puzzleOneResults) {
EXPECT_EQ(2, puzzleOneSolution({Rucksack::builder()
.withCompartmentOneContent(Item{ItemType::a})
.withCompartmentOneContent(Item{ItemType::b})
.withCompartmentTwoContent(Item{ItemType::b})
.withCompartmentTwoContent(Item{ItemType::c})
.build()}));
}
TEST(DayThree, puzzleTwoResults) {
EXPECT_EQ(1, puzzleTwoSolution({
Rucksack::builder()
.withCompartmentOneContent(Item{ItemType::a})
.withCompartmentOneContent(Item{ItemType::b})
.withCompartmentTwoContent(Item{ItemType::b})
.withCompartmentTwoContent(Item{ItemType::c})
.build(),
Rucksack::builder()
.withCompartmentOneContent(Item{ItemType::a})
.withCompartmentOneContent(Item{ItemType::d})
.withCompartmentTwoContent(Item{ItemType::d})
.withCompartmentTwoContent(Item{ItemType::e})
.build(),
Rucksack::builder()
.withCompartmentOneContent(Item{ItemType::a})
.withCompartmentOneContent(Item{ItemType::f})
.withCompartmentTwoContent(Item{ItemType::f})
.withCompartmentTwoContent(Item{ItemType::g})
.build()}));
}
TEST(DayThree, puzzleOneSolution) {
auto input = Parser::parseFilePuzzleOne(Parser::kDayThreeInputFilePath);
EXPECT_EQ(8039, puzzleOneSolution(input));
}
TEST (DayThree, puzzleTwoSolution) {
auto input = Parser::parseFilePuzzleOne(Parser::kDayThreeInputFilePath);
EXPECT_EQ(2510, puzzleTwoSolution(input));
}
TEST(DayThree, benchmarkPuzzleOne) {
DayThree::Input input = Parser::parseFilePuzzleOne(Parser::kDayThreeInputFilePath);
ankerl::nanobench::Bench().run("Day 3 Puzzle 1", [&]() {
ankerl::nanobench::doNotOptimizeAway(DayThree::puzzleOneSolution(input));
});
}
TEST(DayThree, benchmarkPuzzleOneWithStorage) {
ankerl::nanobench::Bench().run("Day 3 Puzzle 1: +Parse +Storage", [&]() {
DayThree::Input input = Parser::parseFilePuzzleOne(Parser::kDayThreeInputFilePath);
ankerl::nanobench::doNotOptimizeAway(DayThree::puzzleOneSolution(input));
});
}
TEST(DayThree, benchmarkPuzzleOneNoStorage) {
ankerl::nanobench::Bench().run("Day 3 Puzzle 1: +Parse -Storage", [&]() {
ankerl::nanobench::doNotOptimizeAway(DayThree::puzzleOneSolutionNoStorage());
});
}
TEST(DayThree, benchmarkPuzzleTwp) {
DayThree::Input input = Parser::parseFilePuzzleOne(Parser::kDayThreeInputFilePath);
ankerl::nanobench::Bench().run("Day 3 Puzzle 2", [&]() {
ankerl::nanobench::doNotOptimizeAway(DayThree::puzzleTwoSolution(input));
});
}
}