forked from KeepCoding/Connecta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquare_board_test.py
70 lines (48 loc) · 2.46 KB
/
square_board_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
import pytest
from square_board import *
def test_empty_board():
board = SquareBoard()
assert board.is_full() == False
assert board.is_victory('o') == False
assert board.is_victory('x') == False
def test_vertical_victory():
vertical = SquareBoard.fromList([['o', 'x', 'x', 'x', ],
[None, None, None, None, ],
[None, None, None, None, ],
[None, None, None, None, ],
[None, None, None, None, ]])
assert vertical.is_victory('x')
assert vertical.is_victory('o') == False
def test_horizontal_victory():
horizontal_victory = SquareBoard.fromList([['x', None, None, None, None, ],
['x', None, None, None, None, ],
['x', 'o', None, None, None, ],
['x', 'o', None, None, None, ],
['x', 'o', None, None, None, ]])
assert horizontal_victory.is_victory('x')
def test_sinking_victory():
sinking_victory = SquareBoard.fromList([['x', 'o', 'x', 'o', ],
['x', 'x', 'o', None, ],
['o', 'o', None, None, ],
['o', 'x', None, None, ],
['x', None, None, None, ]])
assert sinking_victory.is_victory('o')
assert sinking_victory.is_victory('x') == False
def test_rising_victory():
rising_victory = SquareBoard.fromList([['x', 'o', None, None, ],
['o', 'x', None, None, ],
['x', 'o', 'x', 'o', ],
['x', 'o', None, None, ],
])
assert rising_victory.is_victory('x')
assert rising_victory.is_victory('o') == False
def test_board_code():
board = SquareBoard.fromList([['x', 'o', None, None],
['o', 'x', None, None],
['x', 'o', 'x', 'o'],
['x', 'x', 'o', None]])
code = board.as_code()
clone_board = SquareBoard.fromBoardCode(code)
assert clone_board == board
assert clone_board.as_code() == code
assert clone_board.as_code().raw_code == code.raw_code