-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
166 lines (137 loc) · 5.27 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import unittest
import logic
class TestBoard(unittest.TestCase):
def test_initialize_board(self):
board = [['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9']]
board_test = logic.Board()
self.assertEqual(board, board_test.board)
def test_clear_board(self):
board = [['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9']]
board_test = logic.Board()
board_test.board = [['1', '2', 'X'],
['4', 'X', '6'],
['7', 'O', 'O']]
board_test.clear_board()
self.assertEqual(board, board_test.board)
def test_get_winner(self):
board1 = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board2 = [['X', '2', 'O'],
['4', 'O', '6'],
['O', 'O', 'X']]
board3 = [['X', 'X', 'X'],
['4', 'X', '6'],
['7', 'O', 'O']]
board4 = [['X', '2', 'O'],
['4', 'O', 'O'],
['7', 'O', 'O']]
board5 = [['X', '2', 'O'],
['4', 'O', 'X'],
['7', 'O', 'O']]
board6 = [['O', 'X', 'O'],
['O', 'X', 'X'],
['X', 'O', 'O']]
board_test = logic.Board()
board_test.board = board1
self.assertEqual('X', board_test.get_winner())
board_test.board = board2
self.assertEqual('O', board_test.get_winner())
board_test.board = board3
self.assertEqual('X', board_test.get_winner())
board_test.board = board4
self.assertEqual('O', board_test.get_winner())
board_test.board = board5
self.assertEqual(None, board_test.get_winner())
board_test.board = board6
self.assertEqual(None, board_test.get_winner())
def test_get_character_from_index(self):
board = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board_test = logic.Board()
board_test.board = board
self.assertEqual('X', board_test.get_character_from_index(1))
self.assertEqual('6', board_test.get_character_from_index(6))
self.assertEqual('O', board_test.get_character_from_index(8))
def test_check_index(self):
board = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board_test = logic.Board()
board_test.board = board
self.assertEqual(False, board_test.check_index(1))
self.assertEqual(True, board_test.check_index(6))
self.assertEqual(False, board_test.check_index(8))
def test_update_board(self):
board1 = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board1_updated = [['X', 'O', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board2 = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board2_updated = [['X', '2', 'O'],
['4', 'X', 'X'],
['7', 'O', 'X']]
board_test = logic.Board()
board_test.board = board1
board_test.update_board(2, 'O')
self.assertEqual(board1_updated, board_test.board)
board_test.board = board2
board_test.update_board(6, 'X')
self.assertEqual(board2_updated, board_test.board)
board_test.board = board1
board_test.update_board(3, 'O')
self.assertEqual(board1, board_test.board)
board_test.board = board2
board_test.update_board(3, 'X')
self.assertEqual(board2, board_test.board)
def test_check_draw(self):
board1 = [['X', '2', 'O'],
['4', 'X', '6'],
['7', 'O', 'X']]
board2 = [['X', '2', 'O'],
['4', 'O', '6'],
['O', 'O', 'X']]
board3 = [['X', 'O', 'X'],
['4', 'X', '6'],
['7', 'O', 'O']]
board4 = [['X', '2', 'O'],
['4', 'O', 'X'],
['7', 'O', 'O']]
board5 = [['X', 'X', 'O'],
['O', 'O', 'X'],
['X', 'O', 'O']]
board6 = [['O', 'X', 'O'],
['O', 'X', 'X'],
['X', 'O', 'O']]
board_test = logic.Board()
board_test.board = board1
self.assertEqual(False, board_test.check_draw())
board_test.board = board2
self.assertEqual(False, board_test.check_draw())
board_test.board = board3
self.assertEqual(False, board_test.check_draw())
board_test.board = board4
self.assertEqual(False, board_test.check_draw())
board_test.board = board5
self.assertEqual(True, board_test.check_draw())
board_test.board = board6
self.assertEqual(True, board_test.check_draw())
class TestHuman(unittest.TestCase):
def test_initialize_human(self):
player1 = 'O'
player2 = 'X'
test_player1 = logic.Human(player1)
test_player2 = logic.Human(player2)
self.assertEqual(player1, test_player1.player)
self.assertEqual(player2, test_player2.player)
if __name__ == '__main__':
unittest.main()