-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_day_7.cpp
More file actions
111 lines (91 loc) · 2.96 KB
/
Copy pathTest_day_7.cpp
File metadata and controls
111 lines (91 loc) · 2.96 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// Created by Ryan Avery on 12/6/2022.
//
#include <gtest/gtest.h>
#include <fstream>
#include <filesystem>
#include "day_7.h"
namespace Day7 {
std::string testInput = R"($ cd /
$ ls
dir a
14848514 b.txt
8504156 c.dat
dir d
$ cd a
$ ls
dir e
29116 f
2557 g
62596 h.lst
$ cd e
$ ls
584 i
$ cd ..
$ cd ..
$ cd d
$ ls
4060174 j
8033020 d.log
5626152 d.ext
7214296 k
)";
class TestDay7 : public ::testing::Test {
public:
TestDay7() : db(testInput) {}
DirectoryBrowser db;
};
TEST_F(TestDay7, SizeOfDirectories) {
auto dirSizeList = db.getDirSizeList();
ASSERT_EQ(getSizeOfDir(dirSizeList, "e"), 584);
ASSERT_EQ(getSizeOfDir(dirSizeList, "a"), 94853);
ASSERT_EQ(getSizeOfDir(dirSizeList, "d"), 24933642);
ASSERT_EQ(db.getRoot().getSize(), 48381165);
}
TEST_F(TestDay7, SizesOfDirectoriesAtMostASize) {
auto dirSizeList = db.getDirSizeList();
ASSERT_EQ(getSizeOfDirectoriesAtMost(dirSizeList, 100000), 95437);
}
TEST_F(TestDay7, SizeOfDirectoryToDeleteToRunUpdate) {
int totalDiskSpace = 70000000;
int unusedSpaceNeeded = 30000000;
auto unusedSpace = totalDiskSpace - db.getRoot().getSize();
int expectedUnusedSpace = 21618835;
ASSERT_EQ(unusedSpace, expectedUnusedSpace);
int extraSpaceNeeded = unusedSpaceNeeded - unusedSpace;
auto dirSizeList = db.getDirSizeList();
ASSERT_EQ(getDirSizeToDeleteToReclaimSpace(dirSizeList, extraSpaceNeeded), 24933642);
}
TEST(Day7Answer1, SizesOfDirectoriesAtMost) {
const std::filesystem::path dir = INPUTS_DIR;
std::ifstream inFile{dir / "input_day_7.txt"};
ASSERT_TRUE(inFile);
ASSERT_TRUE(inFile.is_open());
std::ostringstream buffer;
buffer << inFile.rdbuf();
std::string str{buffer.str()};
DirectoryBrowser db(str);
auto dirSizeList = db.getDirSizeList();
int size = getSizeOfDirectoriesAtMost(dirSizeList, 100000);
std::cout << "[ DAY 7 ] Total size of directories < 100000 = " << size << std::endl;
ASSERT_EQ(size, 1501149);
}
TEST(Day7Answer2, SizeOfDirectoryToDeleteToRunUpdate) {
const std::filesystem::path dir = INPUTS_DIR;
std::ifstream inFile{dir / "input_day_7.txt"};
ASSERT_TRUE(inFile);
ASSERT_TRUE(inFile.is_open());
std::ostringstream buffer;
buffer << inFile.rdbuf();
std::string str{buffer.str()};
DirectoryBrowser db(str);
int totalDiskSpace = 70000000;
int unusedSpaceNeeded = 30000000;
auto unusedSpace = totalDiskSpace - db.getRoot().getSize();
int extraSpaceNeeded = unusedSpaceNeeded - unusedSpace;
auto dirSizeList = db.getDirSizeList();
int size = getDirSizeToDeleteToReclaimSpace(dirSizeList, extraSpaceNeeded);
std::cout << "[ DAY 7 ] Total size of directories < 100000 = " << size << std::endl;
ASSERT_EQ(size, 10096985);
}
}