def test_print_filled_square(self): """ Printing a square with a piece in it should result in that piece ('X' or 'O'). """ board = Board() board.set_square(1, 'X') self.assertEqual('X', board.print_square(1))
def test_set_square(self): """ Placing a piece should set that square to the specified piece. """ board = Board() self.assertEqual(None, board.get_square(5)) board.set_square(5, 'X') self.assertEqual('X', board.get_square(5))
def test_get_filled_square(self): """ Getting a filled square should return a string of that piece. (For now, might change to using a separate class for pieces later on.) """ board = Board() board.set_square(1, 'X') self.assertEqual('X', board.get_square(1))
def test_get_index_values(self): """ Squares should be fetched using a pattern like a num-pad on a keyboard. The bottom-left square should be square '1', and the top-right square should be square '9'. """ board = Board() board.set_square(3, 'X') self.assertEqual(board.squares[2], board.get_square(3))
def test_squares_equal_with_same_squares(self): """ If all the squares in the list have the same piece in them, the function should return true. """ board = Board() board.set_square(1, 'X') board.set_square(2, 'X') board.set_square(3, 'X') self.assertTrue(board.squares_equal((1, 2, 3)))
def test_squares_equal_with_different_squares(self): """ If the squares aren't the same, the function should return false. """ board = Board() board.set_square(1, 'X') board.set_square(2, 'O') board.set_square(3, 'X') self.assertFalse(board.squares_equal((1, 2, 3)))
def test_game_won_with_no_win(self): """ If the game has not been won by a player yet, the function should return false. """ board = Board() board.set_square(7, 'O') board.set_square(5, 'X') board.set_square(3, 'O') self.assertFalse(board.game_won())
def test_copy_with_filled_board(self): """ Copying a board that has pieces in it should return an exact copy with all the same pieces. """ board = Board() board.set_square(1, 'X') board.set_square(3, 'O') board.set_square(6, 'O') board.set_square(7, 'X') new_board = board.copy() self.assertListEqual(['X', None, 'O', None, None, 'O', 'X', None, None], new_board.squares)
def test_possible_moves_with_some_pieces(self): """ Getting the possible moves from a board should return the square numbers that have no piece in them. """ board = Board() board.set_square(2, 'X') board.set_square(6, 'O') board.set_square(8, 'X') board.set_square(4, 'O') self.assertListEqual( [1, 3, 5, 7, 9], board.get_possible_moves() )
def test_game_won_with_win(self): """ If a player has 3 pieces in a line, the game should be won and the function should return true. The board's winner_piece variable should also be set to the winner's piece. """ board = Board() # make sure board's winner_piece variable is initially None self.assertIsNone(board.winner_piece) board.set_square(7, 'O') board.set_square(5, 'X') board.set_square(3, 'O') board.set_square(8, 'X') board.set_square(1, 'O') board.set_square(4, 'X') board.set_square(2, 'O') self.assertTrue(board.game_won()) self.assertEqual('O', board.winner_piece)