-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07_test.go
78 lines (69 loc) · 1.36 KB
/
07_test.go
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
package main
import "testing"
func TestAOC202207ParseTree(t *testing.T) {
test := struct {
input string
output int
}{
input: `$ 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`,
output: 48381165,
}
fs, err := AOC202207NewFS()
if err != nil {
t.Fatalf("can't create FS: %v", err)
}
err = fs.Populate(test.input)
if err != nil {
t.Fatalf("can't populate FS: %v", err)
}
got := fs.Size()
if got != test.output {
t.Errorf("AOC202207FS.Size() missmatch:\nwant: %d\ngot: %d", test.output, got)
}
dirE, err := fs.GetNode("/a/e")
if err != nil {
t.Fatalf("can't access directory /a/e: %v", err)
}
dirESize := dirE.GetSize()
if dirESize != 584 {
t.Errorf("dirE.GetSize() missmatch:\nwant: 584\ngot: %d", dirESize)
}
dirA, err := fs.GetNode("/a")
if err != nil {
t.Fatalf("can't access directory /a: %v", err)
}
dirASize := dirA.GetSize()
if dirASize != 94853 {
t.Errorf("dirA.GetSize() missmatch:\nwant: 94853\ngot: %d", dirASize)
}
part1 := fs.AOC2022071Helper()
if part1 != 95437 {
t.Errorf("AOC2022071Helper() missmatch:\nwant: 95437\ngot: %d", part1)
}
part2 := fs.AOC2022072Helper()
if part2 != 24933642 {
t.Errorf("AOC2022072Helper() missmatch:\nwant: 24933642\ngot: %d", part2)
}
}