forked from williamhaw/kata_minesweeper
/
test_minesweeper.py
57 lines (42 loc) · 1.9 KB
/
test_minesweeper.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
import minesweeper
class TestMinesweeper:
def test_read_grid_size(self):
input = "4,4"
assert minesweeper.read_grid_size(input) == [4,4]
def test_empty_grid(self):
input = "0,0"
assert minesweeper.read_grid_size(input) == []
def test_empty_mine_list(self):
mines = ""
assert minesweeper.read_mines_from_string(mines, [0,0]) == []
def test_empty_mine_list_with_grid(self):
mines = ""
grid = [2, 3]
assert minesweeper.read_mines_from_string(mines, grid) == [[".", "."], [".", "."], [".", "."]]
def test_read_mines_from_string(self):
mines = """*.."""
assert minesweeper.read_mines_from_string(mines, [3, 1]) == [["*", ".", "."]]
def test_read_multiline_mines(self):
mines = """*..
..."""
assert minesweeper.read_mines_from_string(mines, [3, 2]) == [["*", ".", "."],[".", ".", "."]]
def test_solve(self):
grid = [["*", ".", "."],[".", "*", "."],[".", ".", "."]]
assert minesweeper.solve(grid) == [["*", "2", "1"],["2", "*", "1"],["1", "1", "1"]]
def test_check_and_increment(self):
grid = [[".", ".", "."],[".", "*", "."],[".", ".", "."]]
assert minesweeper.check_and_increment(2, 2, grid) == [[".", ".", "."],[".", "*", "."],[".", ".", "1"]]
def test_check_and_increment_with_existing_number(self):
grid = [["1", ".", "."],[".", "*", "."],[".", ".", "."]]
assert minesweeper.check_and_increment(0, 0, grid) == [["2", ".", "."],[".", "*", "."],[".", ".", "."]]
def test_check_and_increment_with_existing_number(self):
grid = [["*", ".", "."],[".", "*", "."],[".", ".", "."]]
assert minesweeper.check_and_increment(0, 0, grid) == [["*", ".", "."],[".", "*", "."],[".", ".", "."]]
def test_end_to_end(self):
grid_size_str = "3,3"
mines_str = """*..
.*.
..."""
grid_size = minesweeper.read_grid_size(grid_size_str)
grid = minesweeper.read_mines_from_string(mines_str, grid_size)
assert minesweeper.solve(grid) == [["*", "2", "1"],["2", "*", "1"],["1", "1", "1"]]