def test_constructor() -> None: grid = Grid(1, 1) assert grid.columns == 1 assert grid.rows == 1 grid = Grid(2, 2) assert grid.columns == 2 assert grid.rows == 2
def test_constructor() -> None: grid = Grid(2, 2) assert grid.columns == 2 assert grid.rows == 2 grid = Grid(3, 3) assert grid.columns == 3 assert grid.rows == 3
def test_random_cell() -> None: grid = Grid(2, 2) for _ in range(100): assert grid.random_cell() in [ Cell(0, 0), Cell(0, 1), Cell(1, 0), Cell(1, 1) ]
def test_cell_access() -> None: grid = Grid(2, 2) assert grid.get_cell(0, 0) == Cell(0, 0) # type: ignore assert grid.get_cell(0, 1) == Cell(0, 1) # type: ignore assert grid.get_cell(1, 0) == Cell(1, 0) # type: ignore assert grid.get_cell(1, 1) == Cell(1, 1) # type: ignore assert grid.get_cell(-1, 0) is None assert grid.get_cell(0, -1) is None assert grid.get_cell(4, 0) is None assert grid.get_cell(0, 4) is None
def test_cell_access_using_operator_overloads() -> None: grid = Grid(2, 2) assert grid[0, 0] == Cell(0, 0) assert grid[0, 1] == Cell(0, 1) assert grid[1, 0] == Cell(1, 0) assert grid[1, 1] == Cell(1, 1) assert grid[-1, 0] is None assert grid[0, -1] is None assert grid[4, 0] is None assert grid[0, 4] is None
def test_cell_access() -> None: grid = Grid(2, 2) assert grid.cell_at(0, 0) == Cell(0, 0) assert grid.cell_at(0, 1) == Cell(0, 1) assert grid.cell_at(1, 0) == Cell(1, 0) assert grid.cell_at(1, 1) == Cell(1, 1) assert grid.cell_at(-1, 0) is None assert grid.cell_at(0, -1) is None assert grid.cell_at(4, 0) is None assert grid.cell_at(0, 4) is None
def test_neighbors_setup_when_grid_is_created() -> None: grid = Grid(2, 2) assert grid.get_cell(0, 0).north is None # type: ignore assert grid.get_cell(0, 0).south == Cell(1, 0) # type: ignore assert grid.get_cell(0, 0).east == Cell(0, 1) # type: ignore assert grid.get_cell(0, 0).west is None # type: ignore assert grid.get_cell(0, 1).north is None # type: ignore assert grid.get_cell(0, 1).south == Cell(1, 1) # type: ignore assert grid.get_cell(0, 1).east is None # type: ignore assert grid.get_cell(0, 1).west == Cell(0, 0) # type: ignore assert grid.get_cell(1, 0).north == Cell(0, 0) # type: ignore assert grid.get_cell(1, 0).south is None # type: ignore assert grid.get_cell(1, 0).east == Cell(1, 1) # type: ignore assert grid.get_cell(1, 0).west is None # type: ignore assert grid.get_cell(1, 1).north == Cell(0, 1) # type: ignore assert grid.get_cell(1, 1).south is None # type: ignore assert grid.get_cell(1, 1).east is None # type: ignore assert grid.get_cell(1, 1).west == Cell(1, 0) # type: ignore
print("Rotations is an integer value measuring number of 90 degree clockwise rotations to perform") print("Pathfinding flag shows distances between cells") exit(1) exporter, exporter_name = get_exporter(AVAILABLE_EXPORTERS, DEFAULT_EXPORTER) rotations = get_rotations() pathfinding = get_pathfinding() rows = int(args.all[0]) columns = int(args.all[1]) algorithm = get_algorithm() print("Algorithm: {}\nRows: {}\ncolumns: {}\nExporter: {}".format(algorithm.__name__, rows, columns, exporter_name)) print("90deg Rotations: {}\nPathfinding: {}".format(rotations, pathfinding)) if pathfinding: grid = DistanceGrid(rows, columns) # type: Union[Grid, DistanceGrid] else: grid = Grid(rows, columns) grid = algorithm.on(grid) for num in range(rotations): grid = Rotator.on(grid) if pathfinding: start_row, start_column, end_row, end_column = LongestPath.calculate(cast(DistanceGrid, grid)) print("Solving maze from row {} column {} to row {} column {}".format( start_row, start_column, end_row, end_column)) grid = Dijkstra.calculate_distances(cast(DistanceGrid, grid), start_row, start_column, end_row, end_column) exporter.render(grid) print("Maze has {} dead-ends".format(len(grid.deadends)))
def test_size() -> None: assert Grid(1, 1).size() == 1 assert Grid(2, 2).size() == 4 assert Grid(3, 3).size() == 9
def test_size() -> None: assert Grid(2, 2).size == 4 assert Grid(3, 3).size == 9 assert Grid(4, 4).size == 16
from base.grid import Grid from algorithms.binary_tree import BinaryTree from renderers.ascii_renderer import ASCIIRenderer if __name__ == "__main__": grid = Grid(6, 6) grid = BinaryTree.on(grid) ASCIIRenderer.render(grid)