def test_validate_action_False(): """ Check that validate_action is working correctly """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 1, 1, 2, 0, 0], [0, 0, 1, 2, 2, 0, 0], [0, 0, 0, 2, 1, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 2, 0, 0, 0]] board = Board() board.set_board(array) player_1 = Player() result = player_1.validate_action(board, 9) assert (not result)
def test_clear_cell_not_exist(): """ Check that the board not change with value out the range """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 1, 1, 2, 0, 0], [0, 0, 1, 1, 2, 0, 0], [0, 0, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] board = Board() board.set_board(array) position_test = [9, 9] # out the range of board # try to clear cell board.clear_cell(position_test[0], position_test[0]) assert (array == board.board)
def test_clear_cell_exist(): """ Check that cell is clear correctly """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 1, 1, 2, 0, 0], [0, 0, 1, 1, 2, 0, 0], [0, 0, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] board = Board() board.set_board(array) position_test = [0, 0] # at the begin of array # update position in array to compare array[position_test[0]][position_test[1]] = board.null_cell board.clear_cell(position_test[0], position_test[0]) assert (array == board.board)
def test_next_action_block(): """ Check that next_action is working correctly """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 1, 1, 2, 0, 0], [0, 0, 1, 2, 2, 0, 0], [0, 0, 0, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] board = Board() board.set_board(array) player_1 = Agent(1, 2, True) # 1 symbol of the agent, 2 symbol of the opponent player_2 = Agent(2, 1, True) # 2 symbol of the agent, 1 symbol of the opponent col_result = player_2.next_action(board) col = 2 assert(col == col_result)
def test_win_false(): """ Check that win function is working correctly """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 2, 1, 2, 0, 0], [0, 0, 1, 2, 2, 0, 0], [0, 0, 0, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] board = Board() board.set_board(array) player_1 = Agent(1, 2, True) # 1 symbol of the agent, 2 symbol of the opponent player_2 = Agent(2, 1, True) # 2 symbol of the agent, 1 symbol of the opponent col_to_win_result = player_1.win(board, 1) col_to_win = -1 col_to_win_result_2 = player_2.win(board, 2) col_to_win_2 = -1 assert(col_to_win == col_to_win_result) assert(col_to_win_2 == col_to_win_result_2)
def test_block_true(): """ Check that block function is working correctly """ array = [[1, 1, 1, 2, 1, 0, 0], [2, 1, 1, 1, 2, 0, 0], [0, 0, 1, 2, 2, 0, 0], [0, 0, 0, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] board = Board() board.set_board(array) player_1 = Agent(1, 2, True) # 1 symbol of the agent, 2 symbol of the opponent player_2 = Agent(2, 1, True) # 2 symbol of the agent, 1 symbol of the opponent col_to_block_result = player_1.block(board, 2) col_to_block = 4 col_to_block_result_2 = player_2.block(board, 1) col_to_block_2 = 2 assert(col_to_block == col_to_block_result) assert(col_to_block_2 == col_to_block_result_2)