-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboard_test.py
155 lines (90 loc) · 3.41 KB
/
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
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
import unittest
from tic_tac_toe_board import Board
class EmptyBoardTest(unittest.TestCase):
def setUp(self):
self.board = Board()
def test_spaces_are_all_empty(self):
for space in range(0, 9):
self.assertTrue(self.board.is_empty_at(space))
def test_a_marked_space_isnt_empty(self):
self.board.mark(0, 'x')
self.assertFalse(self.board.is_empty_at(0))
def test_a_marked_space_cant_be_remarked(self):
self.board.mark(0, 'x')
with self.assertRaises(ValueError):
self.board.mark(0, 'x')
def test_a_board_with_three_of_the_same_symbol_in_the_first_row_has_a_winner(self):
#First you need a board
#Next you need to check if three of same symbol are in the first row
self.board.mark(0,'x')
self.board.mark(1,'x')
self.board.mark(2,'x')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_in_the_second_row_has_a_winner(self):
self.board.mark(3,'x')
self.board.mark(4,'x')
self.board.mark(5,'x')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_in_the_third_row_has_a_winner(self):
#import pdb; pdb.set_trace()
self.board.mark(6,'x')
self.board.mark(7,'x')
self.board.mark(8,'x')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_in_first_col_has_a_winner(self):
self.board.mark(0,'o')
self.board.mark(3,'o')
self.board.mark(6,'o')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_in_second_col_has_a_winner(self):
self.board.mark(1,'o')
self.board.mark(4,'o')
self.board.mark(7,'o')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_in_third_cols_has_a_winner(self):
self.board.mark(2,'o')
self.board.mark(5,'o')
self.board.mark(8,'o')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_win_by_diagonal_Left_to_right(self):
self.board.mark(0,'o')
self.board.mark(4,'o')
self.board.mark(8,'o')
self.assertTrue(self.board.is_there_a_winner())
def test_a_board_with_three_of_the_same_symbol_win_by_diagonal_right_to_left(self):
self.board.mark(6,'x')
self.board.mark(4,'x')
self.board.mark(2,'x')
self.assertTrue(self.board.is_there_a_winner())
def test_an_empty_board_has_no_winner(self):
self.assertFalse(self.board.is_there_a_winner())
def test_draw_returns_a_string_description_of_the_board(self):
expected_board = """
-------
| | | |
-------
| | | |
-------
| | | |
-------
"""
self.assertEquals(expected_board.strip(), self.board.draw())
def test_draw_returns_a_string_description_of_a_marked_board(self):
expected_board = """
-------
|x|x| |
-------
| | | |
-------
| | | |
-------
"""
self.board.mark(0,'x')
self.board.mark(1,'x')
self.assertEquals(expected_board.strip(), self.board.draw())
# do one for second row, third row
# for diagonals, columns
#who's the winner?
# display the board - return a string representation
if __name__ == '__main__':
unittest.main()