def test_random_cell() -> None: grid = Grid(2, 2) for _ in range(100): assert grid.randomCell() in [ Cell(0, 0), Cell(0, 1), Cell(1, 0), Cell(1, 1) ]
def test_constructor() -> None: grid = Grid(2, 2) assert grid.cols == 2 assert grid.rows == 2 grid = Grid(3, 3) assert grid.cols == 3 assert grid.rows == 3
def test_algorithms_all_run(algorithm: Type[Algorithm]) -> None: for size in TEST_SIZES: grid = Grid(*size) try: algorithm().on(grid) except Exception as ex: raise ex
def test_cell_access() -> 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 # noqa: E201 assert grid[4, 0] is None # noqa: E201 assert grid[0, 4] is None # noqa: E201
def test_exporters_all_run(exporter: Type[Exporter]) -> None: if exporter.__name__ == 'Wolf3DExporter': return # Skip the Wolf3D exporter for a time being for size in TEST_SIZES: grid = Grid(*size) BinaryTree().on(grid) try: # filename = '{}x{}_test_exporters_all_run[{}]'.format(*size, exporter.__name__) filename = 'temp' exporter().render(grid, filename=filename) except Exception as ex: raise ex
def test_neighbors_setup_when_grid_is_created() -> None: grid = Grid(2, 2) assert grid[0, 0].north is None # type: ignore assert grid[0, 0].south == Cell(1, 0) # type: ignore assert grid[0, 0].east == Cell(0, 1) # type: ignore assert grid[0, 0].west is None # type: ignore assert grid[0, 1].north is None # type: ignore assert grid[0, 1].south == Cell(1, 1) # type: ignore assert grid[0, 1].east is None # type: ignore assert grid[0, 1].west == Cell(0, 0) # type: ignore assert grid[1, 0].north == Cell(0, 0) # type: ignore assert grid[1, 0].south is None # type: ignore assert grid[1, 0].east == Cell(1, 1) # type: ignore assert grid[1, 0].west is None # type: ignore # TODO: None Cell class assert grid[1, 1].north == Cell(0, 1) # type: ignore assert grid[1, 1].south is None # type: ignore assert grid[1, 1].east is None # type: ignore assert grid[1, 1].west == Cell(1, 0) # type: ignore
def test_size() -> None: assert Grid(2, 2).size == 4 assert Grid(3, 3).size == 9 assert Grid(4, 4).size == 16
def __init__(self, board_size): Grid.__init__(self, cell = lambda me: cell.empty(), board_size=board_size)
print('Rows: {}\ncolumns: {}\nTotal cells: {}\nRuns per algorithm: {}'. format(rows, columns, size, tries)) print('Pathfinding: {}'.format(pathfinding)) for algorithm in ALGORITHMS: print('> running {}'.format(algorithm.__name__)) pathfinding_timings = [] timings = [] deadend_counts = [] for _ in range(tries): if pathfinding: grid = DistanceGrid(rows, columns) # type: Union[Grid, DistanceGrid] else: grid = Grid(rows, columns) time_start = time.perf_counter() algorithm().on(grid) time_end = time.perf_counter() deadend_counts.append(len(grid.deadends)) timings.append(time_end - time_start) if pathfinding: time_start = time.perf_counter() start, end = LongestPath.calculate(cast(DistanceGrid, grid)) Dijkstra.calculate_distances(cast(DistanceGrid, grid), start, end) time_end = time.perf_counter() pathfinding_timings.append(time_end - time_start)