-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
71 lines (59 loc) · 1.76 KB
/
tests.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
import pytest
from .utils import Board, CellContents, Grid
@pytest.mark.parametrize(
"test_input, expected",
[
("#", CellContents.Unclicked()),
(".", CellContents.Num(0)),
("0", CellContents.Num(0)),
("1", CellContents.Num(1)),
("5", CellContents.Num(5)),
("F", CellContents.Flag(1)),
("F1", CellContents.Flag(1)),
("F2", CellContents.Flag(2)),
("X2", CellContents.WrongFlag(2)),
("M1", CellContents.Mine(1)),
("!", CellContents.HitMine(1)),
],
)
def test_cell_contents_from_str(test_input: str, expected: CellContents):
assert CellContents.from_string(test_input) == expected
@pytest.mark.parametrize(
"test_input, expected",
[
(CellContents.Unclicked(), "#"),
(CellContents.Num(0), "."),
(CellContents.Num(1), "1"),
(CellContents.Num(5), "5"),
(CellContents.Flag(1), "F1"),
(CellContents.Flag(2), "F2"),
(CellContents.WrongFlag(2), "X2"),
(CellContents.Mine(1), "M1"),
(CellContents.HitMine(1), "!1"),
],
)
def test_cell_contents_to_str(test_input: CellContents, expected: str):
assert test_input.to_string() == expected
def test_create_grid():
Grid(3, 4)
def test_create_board():
Board(3, 4)
def test_create_board_from_str():
board = Board.from_str(
"""
# . 1 2
# 3 F !2
"""
)
assert board.x_size == 4
assert board.y_size == 2
assert list(board.values) == [
CellContents.Unclicked(),
CellContents.Num(0),
CellContents.Num(1),
CellContents.Num(2),
CellContents.Unclicked(),
CellContents.Num(3),
CellContents.Flag(1),
CellContents.HitMine(2),
]