-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_game.py
94 lines (74 loc) · 2.06 KB
/
test_game.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import pytest
from game import Game, EMPTY, X, O, get_player, is_over, get_winner, get_available_actions
class TestGame:
def test_get_player_first_move(self):
board = [
[EMPTY, EMPTY, EMPTY],
[EMPTY, EMPTY, EMPTY],
[EMPTY, EMPTY, EMPTY]
]
assert get_player(board) == X
def test_get_player_O(self):
board = [
[EMPTY, O, EMPTY],
[EMPTY, X, EMPTY],
[EMPTY, X, EMPTY]
]
assert get_player(board) == O
def test_get_player_X(self):
board = [
[O, EMPTY, EMPTY],
[EMPTY, EMPTY, X],
[EMPTY, EMPTY, EMPTY]
]
assert get_player(board) == X
def test_apply_action(self):
game = Game()
game.board = [
[O, EMPTY, O],
[EMPTY, EMPTY, X],
[X, EMPTY, EMPTY]
]
game.apply_action((0, 1))
expected_board = [
[O, X, O],
[EMPTY, EMPTY, X],
[X, EMPTY, EMPTY]
]
assert game.board == expected_board
def test_get_winner_none(self):
board = [
[EMPTY, EMPTY, EMPTY],
[O, X, EMPTY],
[O, X, EMPTY]
]
assert get_winner(board) == None
def test_get_winner(self):
board = [
[EMPTY, X, EMPTY],
[O, X, EMPTY],
[O, X, EMPTY]
]
assert get_winner(board) == X
def test_is_over_false(self):
board = [
[EMPTY, X, EMPTY],
[O, X, EMPTY],
[O, X, EMPTY]
]
assert is_over(board) == False
def test_is_over_true(self):
board = [
[X, O, X],
[O, X, X],
[O, X, O]
]
assert is_over(board) == True
def test_get_available_actions(self):
board = [
[EMPTY, EMPTY, EMPTY],
[O, X, EMPTY],
[O, X, EMPTY]
]
expected = {(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)}
assert get_available_actions(board) == expected