-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_day14.py
73 lines (64 loc) · 1.53 KB
/
test_day14.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
from day14 import Cave
filename = 'inputs/2022/day14-test.txt'
initial_grid = '''0 ......+...
1 ..........
2 ..........
3 ..........
4 ....#...##
5 ....#...#.
6 ..###...#.
7 ........#.
8 ........#.
9 #########.
'''
with_floor = '''............o............
...........ooo...........
..........ooooo..........
.........ooooooo.........
........oo#ooo##o........
.......ooo#ooo#ooo.......
......oo###ooo#oooo......
.....oooo.oooo#ooooo.....
....oooooooooo#oooooo....
...ooo#########ooooooo...
..ooooo.......ooooooooo..
#########################
'''
def test_cave_init():
cave = Cave(filename)
assert cave.data
def test_cave_bounds():
cave = Cave(filename)
assert cave.bounds == {
'min_x': 494,
'max_x': 503,
'min_y': 0,
'max_y': 9
}
def test_cave_draw_no_floor(capfd):
cave = Cave(filename)
cave.draw(row_numbers=True)
out, _ = capfd.readouterr()
assert out == initial_grid
def test_cave_draw_floor(capfd):
cave = Cave(filename)
cave.draw(row_numbers=True)
out, _ = capfd.readouterr()
assert out == initial_grid
def test_cave_drop_grain():
cave = Cave(filename)
cave.drop_grain(False)
assert cave.grid[8][500] == 'o'
cave.drop_grain(False)
assert cave.grid[8][499] == 'o'
cave.drop_grain(False)
assert cave.grid[8][501] == 'o'
cave.drop_grain(False)
assert cave.grid[7][500] == 'o'
cave.drop_grain(False)
assert cave.grid[8][498] == 'o'
def test_cave_keep_pouring():
cave = Cave(filename)
assert cave.keep_pouring(False) == 24
cave = Cave(filename)
assert cave.keep_pouring(True) == 93