-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_aoc_13.py
85 lines (71 loc) · 1.78 KB
/
test_aoc_13.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
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
import aoc_13 as target
def test_parse():
grid, folds = target.parse(puzzle_input=example)
assert grid_to_paper(grid) == example_paper
assert folds == example_folds
def test_count_the_dots():
assert target.count_the_dots(target.turn_to_grid(example_dots)) == example_paper.count('#')
fold_1 = target.fold_paper(target.turn_to_grid(example_dots), example_folds[0][0], example_folds[0][1])
assert target.count_the_dots(fold_1) == 17
fold_2 = target.fold_paper(fold_1, example_folds[1][0], example_folds[1][1])
assert target.count_the_dots(fold_2) == example_fold_2.count('#')
def test_fold_paper():
fold_1 = target.fold_paper(target.turn_to_grid(example_dots),example_folds[0][0],example_folds[0][1])
assert grid_to_paper(fold_1) == example_fold_1
fold_2 = target.fold_paper(fold_1,example_folds[1][0],example_folds[1][1])
assert grid_to_paper(fold_2) == example_fold_2
def grid_to_paper(grid):
return '\n'.join([''.join(['#' if c>0 else '.' for c in line]) for line in grid])
def test_turn_to_grid():
assert grid_to_paper(target.turn_to_grid(example_dots)) == example_paper
example = """6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
10,12
3,4
3,0
8,4
1,10
2,14
8,10
9,0
fold along y=7
fold along x=5"""
example_dots = [(6,10),(0,14),(9,10),(0,3),(10,4),(4,11),(6,0),(6,12),(4,1),(0,13),(10,12),(3,4),(3,0),(8,4),(1,10),(2,14),(8,10),(9,0)]
example_folds = [(True,7),(False,5)]
example_paper = """...#..#..#.
....#......
...........
#..........
...#....#.#
...........
...........
...........
...........
...........
.#....#.##.
....#......
......#...#
#..........
#.#........"""
example_fold_1 = """#.##..#..#.
#...#......
......#...#
#...#......
.#.#..#.###
...........
..........."""
example_fold_2 = """#####
#...#
#...#
#...#
#####
.....
....."""