forked from reingart/exercism
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathminesweeper_test.py
76 lines (58 loc) · 2.59 KB
/
minesweeper_test.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
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/minesweeper/canonical-data.json
# File last updated on 2023-07-19
import unittest
from minesweeper import (
annotate,
)
class MinesweeperTest(unittest.TestCase):
def test_no_rows(self):
self.assertEqual(annotate([]), [])
def test_no_columns(self):
self.assertEqual(annotate([""]), [""])
def test_no_mines(self):
self.assertEqual(annotate([" ", " ", " "]), [" ", " ", " "])
def test_minefield_with_only_mines(self):
self.assertEqual(annotate(["***", "***", "***"]), ["***", "***", "***"])
def test_mine_surrounded_by_spaces(self):
self.assertEqual(annotate([" ", " * ", " "]), ["111", "1*1", "111"])
def test_space_surrounded_by_mines(self):
self.assertEqual(annotate(["***", "* *", "***"]), ["***", "*8*", "***"])
def test_horizontal_line(self):
self.assertEqual(annotate([" * * "]), ["1*2*1"])
def test_horizontal_line_mines_at_edges(self):
self.assertEqual(annotate(["* *"]), ["*1 1*"])
def test_vertical_line(self):
self.assertEqual(annotate([" ", "*", " ", "*", " "]), ["1", "*", "2", "*", "1"])
def test_vertical_line_mines_at_edges(self):
self.assertEqual(annotate(["*", " ", " ", " ", "*"]), ["*", "1", " ", "1", "*"])
def test_cross(self):
self.assertEqual(
annotate([" * ", " * ", "*****", " * ", " * "]),
[" 2*2 ", "25*52", "*****", "25*52", " 2*2 "],
)
def test_large_minefield(self):
self.assertEqual(
annotate([" * * ", " * ", " * ", " * *", " * * ", " "]),
["1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111"],
)
# Additional tests for this track
def test_annotate_9(self):
self.assertEqual(
annotate([" ", " * ", " ", " ", " * "]),
[" 111", " 1*1", " 111", "111 ", "1*1 "],
)
def test_different_len(self):
with self.assertRaises(ValueError) as err:
annotate([" ", "* ", " "])
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(
err.exception.args[0], "The board is invalid with current input."
)
def test_invalid_char(self):
with self.assertRaises(ValueError) as err:
annotate(["X * "])
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(
err.exception.args[0], "The board is invalid with current input."
)