def test_draw_boards(self): boards = [{ 'board': [['X', 'O', 'X'], ['X', 'O', 'X'], ['O', 'X', 'O']], 'winner': None }, { 'board': [['O', 'X', 'O'], ['O', 'X', 'X'], ['X', 'O', 'X']], 'winner': None }] for item in boards: self.assertEqual(ttt.winner(item['board']), item['winner'])
def test_diagonal_boards(self): boards = [{ 'board': [['O', '·', 'X'], ['·', 'X', '·'], ['X', '·', 'O']], 'winner': 'X' }, { 'board': [['O', 'X', 'X'], ['·', 'O', '·'], ['X', 'O', 'O']], 'winner': 'O' }] for item in boards: self.assertEqual(ttt.winner(item['board']), item['winner'])
def test_X_won_vertical_begin(self): moves = 'xo_' \ 'xo_' \ 'x__' self.assertEqual(winner(moves), X)
def test_O_won_diagonal_right_to_left(self): moves = 'x_o' \ 'xo_' \ 'o__' self.assertEqual(winner(moves), O)
def test_O_won_diagonal_left_to_right(self): moves = 'ox_' \ 'xo_' \ '__o' self.assertEqual(winner(moves), O)
def test_X_won_diagonal_right_to_left(self): moves = 'o_x' \ 'ox_' \ 'x__' self.assertEqual(winner(moves), X)
def test_X_won_diagonal_left_to_right(self): moves = 'xo_' \ 'ox_' \ '__x' self.assertEqual(winner(moves), X)
def test_O_won_vertical_begin(self): moves = 'ox_' \ 'ox_' \ 'o__' self.assertEqual(winner(moves), O)
def test_O_won_horizontal_begin(self): moves = 'ooo' \ 'x_x' \ '___' self.assertEquals(winner(moves), O)
def test_X_won_horizontal_end(self): moves = '___' \ 'o_o' \ 'xxx' self.assertEquals(winner(moves), X)
def test_X_won_horizontal_middle(self): moves = '_o_' \ 'xxx' \ 'o_o' self.assertEquals(winner(moves), X)
def test_tie_2(self): moves = 'xox' \ 'oxo' \ 'oxo' self.assertEqual(winner(moves), TIE)
def test_X_won_horizontal_begin(self): moves = 'xxx' \ 'o_o' \ '___' self.assertEquals(winner(moves), X)
def test_O_won_vertical_end(self): moves = '__o' \ 'x_o' \ 'x_o' self.assertEqual(winner(moves), O)
def test_X_won_vertical_middle(self): moves = '_xo' \ '_xo' \ '_x_' self.assertEqual(winner(moves), X)
def test_O_won_horizontal_middle(self): moves = '_x_' \ 'ooo' \ 'x_x' self.assertEquals(winner(moves), O)
def test_X_won_vertical_end(self): moves = '__x' \ 'o_x' \ 'o_x' self.assertEqual(winner(moves), X)
def test_O_won_horizontal_end(self): moves = '___' \ 'x_x' \ 'ooo' self.assertEquals(winner(moves), O)
def test_O_won_vertical_middle(self): moves = '_ox' \ '_ox' \ '_o_' self.assertEqual(winner(moves), O)
def test_winning_board_state(self): self.game.grid = 'xxx ' self.assertEqual(winner(self.game.grid), 'x') self.game.grid = 'xoxoxoxox' self.assertEqual(winner(self.game.grid), 'x')