def test_reusability(correct_board): solver = board_solver(correct_board) assert solver(1, 1) == [11, 34, 42, 15, 25, 31, 54, 13, 32, 45, 35, 23, 43, 51, 21, 14, 41, 33, 52] # Same solver should be reusable with different starting point assert solver(2, 2) == [22, 42, 15, 25, 31, 54, 13, 32, 45, 35, 23, 43, 51, 21, 14, 41, 33, 52]
def main(board_map): version = input( 'Choose between OO(o) and Functional(f) versions and press [Enter] or [q] to quit: ' ).lower() if version == 'o': board = Board(board_map) TreasureSolver(board).solve() elif version == 'f': solver = board_solver(board_map) try: result = solver(1, 1) print(f'Output: {", ".join([str(x) for x in result])}') except RecursionError as exc: print( f'This board can not be solved using {exc.args[0]} as first step' ) elif version == 'q': sys.exit("Bye, bye!") else: main(board_map)
def test_solving_correct_board(correct_board): solver = board_solver(correct_board) assert solver() == [ 11, 34, 42, 15, 25, 31, 54, 13, 32, 45, 35, 23, 43, 51, 21, 14, 41, 33, 52]
def test_solving_incorrect_board(incorrect_board): solver = board_solver(incorrect_board) with pytest.raises(RecursionError) as exc_info: solver()
def test_equal_results(correct_board): """Results should be equal for both implementations""" result_1 = TreasureSolver(Board(correct_board)).solve() result_2 = board_solver(correct_board)() assert result_1 == result_2