-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aoc_10.py
58 lines (43 loc) · 1.69 KB
/
test_aoc_10.py
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
import aoc_10 as target
def test_parse():
assert target.parse(example_data) == example_lines
def test_complete_line():
for line in example_lines:
try:
completion = target.complete_line(line)
except target.CorruptedException:
assert line in example_corrupted
else:
assert line not in example_corrupted
assert ''.join(completion) == example_incomplete[line][0]
example_data = """[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]"""
example_lines = example_data.splitlines()
example_corrupted = [
"{([(<{}[<>[]}>{[]{[(<()>", # Expected ], but found } instead.
"[[<[([]))<([[{}[[()]]]", # Expected ], but found ) instead.
"[{[{({}]{}}([{[{{{}}([]", # Expected ), but found ] instead.
"[<(<(<(<{}))><([]([]()", # Expected >, but found ) instead.
"<{([([[(<>()){}]>(<<{{"]
example_incomplete = {
"[({(<(())[]>[[{[]{<()<>>": ("}}]])})]", 288957),
"[(()[<>])]({[<{<<[]>>(": (")}>]})", 5566),
"(((({<>}<{<{<>}{[]{[]{}": ("}}>}>))))", 1480781),
"{<[[]]>}<{[{[{[]{()[[[]": ("]]}}]}]}>", 995444),
"<{([{{}}[<[[[<>{}]]]>[]]": ("])}>", 294)}
def test_part1():
assert target.part1(example_data) == 26397
def test_score_completion():
for completion, score in example_incomplete.values():
assert target.score_completion(completion) == score
def test_determine_middle_number():
scores = [score for (_,score) in example_incomplete.values()]
assert target.determine_middle_number(scores) == 288957