Example #1
0
    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'])
Example #2
0
    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'])
Example #3
0
 def test_X_won_vertical_begin(self):
     moves = 'xo_' \
             'xo_' \
             'x__'
     self.assertEqual(winner(moves), X)
Example #4
0
 def test_O_won_diagonal_right_to_left(self):
     moves = 'x_o' \
             'xo_' \
             'o__'
     self.assertEqual(winner(moves), O)
Example #5
0
 def test_O_won_diagonal_left_to_right(self):
     moves = 'ox_' \
             'xo_' \
             '__o'
     self.assertEqual(winner(moves), O)
Example #6
0
 def test_X_won_diagonal_right_to_left(self):
     moves = 'o_x' \
             'ox_' \
             'x__'
     self.assertEqual(winner(moves), X)
Example #7
0
 def test_X_won_diagonal_left_to_right(self):
     moves = 'xo_' \
             'ox_' \
             '__x'
     self.assertEqual(winner(moves), X)
Example #8
0
 def test_O_won_vertical_begin(self):
     moves = 'ox_' \
             'ox_' \
             'o__'
     self.assertEqual(winner(moves), O)
Example #9
0
 def test_O_won_horizontal_begin(self):
     moves = 'ooo' \
             'x_x' \
             '___'
     self.assertEquals(winner(moves), O)
Example #10
0
 def test_X_won_horizontal_end(self):
     moves = '___' \
             'o_o' \
             'xxx'
     self.assertEquals(winner(moves), X)
Example #11
0
 def test_X_won_horizontal_middle(self):
     moves = '_o_' \
             'xxx' \
             'o_o'
     self.assertEquals(winner(moves), X)
Example #12
0
 def test_tie_2(self):
     moves = 'xox' \
             'oxo' \
             'oxo'
     self.assertEqual(winner(moves), TIE)
Example #13
0
 def test_X_won_horizontal_begin(self):
     moves = 'xxx' \
             'o_o' \
             '___'
     self.assertEquals(winner(moves), X)
Example #14
0
 def test_O_won_vertical_end(self):
     moves = '__o' \
             'x_o' \
             'x_o'
     self.assertEqual(winner(moves), O)
Example #15
0
 def test_X_won_vertical_middle(self):
     moves = '_xo' \
             '_xo' \
             '_x_'
     self.assertEqual(winner(moves), X)
Example #16
0
 def test_O_won_horizontal_middle(self):
     moves = '_x_' \
             'ooo' \
             'x_x'
     self.assertEquals(winner(moves), O)
Example #17
0
 def test_X_won_vertical_end(self):
     moves = '__x' \
             'o_x' \
             'o_x'
     self.assertEqual(winner(moves), X)
Example #18
0
 def test_O_won_horizontal_end(self):
     moves = '___' \
             'x_x' \
             'ooo'
     self.assertEquals(winner(moves), O)
Example #19
0
 def test_O_won_vertical_middle(self):
     moves = '_ox' \
             '_ox' \
             '_o_'
     self.assertEqual(winner(moves), O)
Example #20
0
    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')