def test_next_move_on_full_board(self): board = BaseBoard(3) board.board_state = {1:"x", 2:"o", 3:"x", 4:"o", 5:"x", 6:"x", 7:"x", 8:"o", 9:"o"} ai = ImpossibleAI("x") self.assertEqual(None,ai.next_move(board))
def test_it_with_four_by_four(self): board = BaseBoard(4) board.board_state = {1: "x", 2: "x", 3: "x", 5: "o", 6: "o", 7: "o", 8: "x", 9: "x", 10: "o", 11: "x", 12: "x", 13: "o", 14: "x", 15: "o", 16: "x"} self.assertEqual(4,self.x_minimax.next_move(board))
def test_winner_with_tie(self): board = BaseBoard(base=3) board.board_state = {1:"x",2:"x",3:"o", 4:"o",5:"x",6:"x", 7:"x",8:"o",9:"o"} self.assertTrue(board.is_full()) self.assertEqual(None,board.winner())
def test_over_with_full_fours_board(self): board = BaseBoard(4) board.board_state = {1:"o",2:"x",3:"x",4:"o", 5:"x",6:"o",7:"o",8:"x", 9:"x",10:"o",11:"o",12:"x", 13:"x",14:"x",15:"o",16:"x"} self.assertFalse(board.winner()) self.assertTrue(board.over())
def test_format_for_speech(self): board = BaseBoard(3) board.board_state = {1:"x", 8:"o", 9:"x"} board_string = board.__str__() row_one = " row 1 x empty empty" row_two = " row 2 empty empty empty" row_three = " row 3 empty o x" expected = (row_one + row_two + row_three) self.assertEqual(expected,self.formatter.format_for_speech(board_string))
def test_format_for_speech(self): board = BaseBoard(3) board.board_state = {1: "x", 8: "o", 9: "x"} board_string = board.__str__() row_one = " row 1 x empty empty" row_two = " row 2 empty empty empty" row_three = " row 3 empty o x" expected = (row_one + row_two + row_three) self.assertEqual(expected, self.formatter.format_for_speech(board_string))
def test_format_for_speech_with_fours_board(self): board = BaseBoard(4) board.board_state = {1:"x", 8:"o", 9:"x"} board_string = board.__str__() row_one = " row 1 x empty empty empty" row_two = " row 2 empty empty empty o" row_three = " row 3 x empty empty empty" row_four = " row 4 empty empty empty empty" expected = (row_one + row_two + row_three + row_four) self.assertTrue(self.fours_formatter.is_board_string(board_string)) self.assertEqual(expected,self.fours_formatter.format_for_speech(board_string))
def test_format_for_speech_with_fours_board(self): board = BaseBoard(4) board.board_state = {1: "x", 8: "o", 9: "x"} board_string = board.__str__() row_one = " row 1 x empty empty empty" row_two = " row 2 empty empty empty o" row_three = " row 3 x empty empty empty" row_four = " row 4 empty empty empty empty" expected = (row_one + row_two + row_three + row_four) self.assertTrue(self.fours_formatter.is_board_string(board_string)) self.assertEqual(expected, self.fours_formatter.format_for_speech(board_string))
def test_next_move_on_full_board(self): board = BaseBoard(3) board.board_state = { 1: "x", 2: "o", 3: "x", 4: "o", 5: "x", 6: "x", 7: "x", 8: "o", 9: "o" } ai = ImpossibleAI("x") self.assertEqual(None, ai.next_move(board))
def test_it_with_four_by_four(self): board = BaseBoard(4) board.board_state = { 1: "x", 2: "x", 3: "x", 5: "o", 6: "o", 7: "o", 8: "x", 9: "x", 10: "o", 11: "x", 12: "x", 13: "o", 14: "x", 15: "o", 16: "x" } self.assertEqual(4, self.x_minimax.next_move(board))
def test_winner(self): board = BaseBoard(base=3) board.board_state = {1:"me",2:"me",3:"me"} self.assertEqual("me",board.winner())
def test_it_with_two_by_two(self): board = BaseBoard(2) board.board_state = {1:"x",3:"shoe",4:"moo"} self.assertEqual(2,self.x_minimax.next_move(board))
def test_available_moves_with_win_board(self): board = BaseBoard(3) board.board_state = {1:"o",2:"o",3:"o"} # Board assumes available moves not called when game over self.assertEqual(range(4,10),board.available_moves())
def test_available_moves_with_full_board(self): board = BaseBoard(3) board.board_state = {1:"o",2:"o",3:"x", 4:"x",5:"x",6:"o", 7:"o",8:"o",9:"x"} self.assertEqual([],board.available_moves())
def test_state_returns_only_non_junk(self): garbage_state = {0:"", 5:"o", 6:"x", 9:"x"} board = BaseBoard(3) board.board_state = garbage_state self.assertEqual( {5:"o", 6:"x", 9:"x"}, board.state())
def test_full_with_fours_board(self): board = BaseBoard(4) board.board_state = {1:"o",2:"o",3:"x", 4:"x",5:"x",6:"o", 7:"o",8:"o",9:"x"} self.assertFalse(board.is_full())
def test_player_with_easy_ai(self): player = PlayerFactory.player("EasyAI","o") self.assertTrue(isinstance(player,ImpossibleAI)) board = BaseBoard(3) board.board_state = {1:"x",2:"x"} self.assertTrue(player.next_move(board) != 3)
def test_next_move_on_board_thats_won(self): board = BaseBoard(3) board.board_state = {1: "x", 2: "x", 3: "x"} ai = ImpossibleAI("x") self.assertEqual(None, ai.next_move(board))
def test_next_move_on_board_thats_won(self): board = BaseBoard(3) board.board_state = {1:"x", 2:"x", 3:"x"} ai = ImpossibleAI("x") self.assertEqual(None,ai.next_move(board))
def test_available_moves_with_partial_board(self): board = BaseBoard(3) board.board_state = {1:"x",5:"o"} self.assertEqual(range(2,5)+range(6,10),board.available_moves())
def test_over_with_full_threes_board(self): board = BaseBoard(3) board.board_state = {1:"x",2:"x",3:"o", 4:"o",5:"x",6:"x", 7:"x",8:"o",9:"o"} self.assertEqual(True,board.over())
def test_over_with_win(self): self.assertFalse(BaseBoard(base=3).over()) board = BaseBoard(base=3) board.board_state = {1:"x",2:"x",3:"x"} self.assertTrue(board.over())
def test_over_with_non_full_board(self): board = BaseBoard(3) board.board_state = {1:"x", 2:"o"} self.assertFalse(board.over())
def test_it_with_two_by_two(self): board = BaseBoard(2) board.board_state = {1: "x", 3: "shoe", 4: "moo"} self.assertEqual(2, self.x_minimax.next_move(board))
def test_winner_with_twos_board(self): board = BaseBoard(base=2) board.board_state = {1:"you",4:"you"} self.assertEqual("you",board.winner())
def test_next_move_on_board_won_with_other_token(self): board = BaseBoard(3) board.board_state = {1:"o", 2:"o", 3:"o"} ai = ImpossibleAI("x") self.assertEqual(None,ai.next_move(board))
def test_winner_with_no_win(self): board = BaseBoard(base=3) board.board_state = {1:"x",2:"x",3:"o"} self.assertEqual(None,board.winner())
def test_integration_with_default_minimax(self): ai = ImpossibleAI("x") board = BaseBoard(3) board.board_state = {1:"x", 2:"x"} move = ai.next_move(board) self.assertEqual(3,move)
def test_full_on_full_board(self): board = BaseBoard(base=3) board.board_state = {1:"o",2:"o",3:"x", 4:"x",5:"x",6:"o", 7:"o",8:"o",9:"x"} self.assertTrue(board.is_full())
def test_next_move_on_board_won_with_other_token(self): board = BaseBoard(3) board.board_state = {1: "o", 2: "o", 3: "o"} ai = ImpossibleAI("x") self.assertEqual(None, ai.next_move(board))
def test_full_with_win(self): board = BaseBoard(3) board.board_state = {1:"x",2:"x",3:"x"} self.assertFalse(board.is_full())
def test_integration_with_default_minimax(self): ai = ImpossibleAI("x") board = BaseBoard(3) board.board_state = {1: "x", 2: "x"} move = ai.next_move(board) self.assertEqual(3, move)
def test_player_with_easy_ai(self): player = PlayerFactory.player("EasyAI", "o") self.assertTrue(isinstance(player, ImpossibleAI)) board = BaseBoard(3) board.board_state = {1: "x", 2: "x"} self.assertTrue(player.next_move(board) != 3)