def test_good_map(example_map, capsys): extracted_map = map_utils.extract_map(example_map) assert find_square.MapSolver.check(extracted_map) == True my_map = find_square.MapSolver(extracted_map) my_map.solve() captured = capsys.readouterr() assert ( captured.out == ".....xxxxxxx...............\n....oxxxxxxx...............\n.....xxxxxxxo..............\n.....xxxxxxx...............\n....oxxxxxxx...............\n.....xxxxxxx...o...........\n.....xxxxxxx...............\n......o..............o.....\n..o.......o................\n" )
def run(args): for arg in args[1:]: given_map = map_utils.extract_map(arg) if MapSolver.check(given_map): map_solver = MapSolver(given_map) map_solver.solve(save_to_file=True)
import random try: proj_base_path = os.path.realpath( os.path.join(os.path.dirname(__file__), "..", "..", "materials")) sys.path.append(proj_base_path) import map_gen except ModuleNotFoundError: proj_base_path = os.path.realpath( os.path.join(os.path.dirname(__file__), "materials")) sys.path.append(proj_base_path) import map_gen old_stdout = sys.stdout new_stdout = io.StringIO() sys.stdout = new_stdout map_gen.map_gen(random.randint(0, 20), random.randint(0, 20), random.randint(1, 5)) output = new_stdout.getvalue() sys.stdout = old_stdout print("##### GENERATED MAP #####") print(output) print("##### GENERATED MAP #####") given_map = map_utils.extract_map(output) if MapSolver.check(given_map): map_solver = MapSolver(given_map) map_solver.solve(save_to_file=False)
def test_wrong_char_map(bad_map_char, capsys): extracted_map = map_utils.extract_map(bad_map_char) assert find_square.MapSolver.check(extracted_map) == False captured = capsys.readouterr() assert captured.err == "map error\n"