Exemplo n.º 1
0
    def test_o_wins(self):
        board = TicTacToeBoard()
        board["C3"] = "O"
        board["A3"] = "X"
        board["B2"] = "O"
        board["B1"] = "X"
        board["A1"] = "O"

        self.assertEqual("O wins!", board.game_status())
Exemplo n.º 2
0
    def test_print_empty_board(self):
        board = TicTacToeBoard()
        empty_board = """
  -------------
3 |   |   |   |
  -------------
2 |   |   |   |
  -------------
1 |   |   |   |
  -------------
    A   B   C
"""
        self.assertEqual(empty_board.strip(), str(board).strip())
Exemplo n.º 3
0
    def test_draw(self):
        board = TicTacToeBoard()
        board["A1"] = 'O'
        board["B1"] = 'X'
        board["A3"] = 'O'
        board["A2"] = 'X'
        board["C2"] = 'O'
        board["C3"] = 'X'
        board["B3"] = 'O'
        board["B2"] = 'X'
        board["C1"] = 'O'

        self.assertEqual('Draw!', board.game_status())
Exemplo n.º 4
0
    def test_print_full_board(self):
        board = TicTacToeBoard()
        board_str = """
  -------------
3 | X | X | X |
  -------------
2 | O | O | X |
  -------------
1 | O | X | O |
  -------------
    A   B   C
"""
        board["A3"] = "X"
        board["A2"] = "O"
        board["B3"] = "X"
        board["B2"] = "O"
        board["C3"] = "X"
        board["C1"] = "O"
        board["C2"] = "X"
        board["A1"] = "O"
        board["B1"] = "X"
        self.assertEqual(board_str.strip(), str(board).strip())
Exemplo n.º 5
0
 def test_move_when_cell_number_before_letter_raises(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidKey):
         board["1B"] = "X"
Exemplo n.º 6
0
 def test_game_in_progress_when_board_instantiated(self):
     board = TicTacToeBoard()
     self.assertEqual("Game in progress.", board.game_status())
Exemplo n.º 7
0
 def test_move_twice_with_same_value(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.NotYourTurn):
         board["A1"] = 'X'
         board["B1"] = 'X'
Exemplo n.º 8
0
 def test_move_twice_on_same_cell(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidMove):
         board["A1"] = 'X'
         board["A1"] = 'O'
Exemplo n.º 9
0
 def test_can_move_when_cell_valid(self):
     board = TicTacToeBoard()
     board["B1"] = "X"
     board["C1"] = "O"
     self.assertEqual(board["B1"], "X")
     self.assertEqual(board["C1"], "O")
Exemplo n.º 10
0
 def test_move_when_invalid_value(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidValue):
         board["B3"] = "d"
Exemplo n.º 11
0
 def test_move_when_cell_has_invalid_number(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidKey):
         board["B8"] = "X"
Exemplo n.º 12
0
 def test_move_when_cell_is_invalid_letter(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidKey):
         board["Z"] = "X"
Exemplo n.º 13
0
 def test_move_when_cell_is_just_a_number(self):
     board = TicTacToeBoard()
     with self.assertRaises(solution.InvalidKey):
         board["1"] = "X"
Exemplo n.º 14
0
    def test_game_in_progress(self):
        board = TicTacToeBoard()
        board["A1"] = 'X'
        board["A3"] = 'O'

        self.assertEqual('Game in progress.', board.game_status())
Exemplo n.º 15
0
 def setUp(self):
     self.board = TicTacToeBoard()