def _rotate_cell_neighbors(self, new: Cell, old: Cell, grid: Grid) -> None: for link in old.links: row, col = self._rotated_coordinates(link, grid) neighbor = grid[row, col] if neighbor is None: raise IndexError('Cell not found at row {} column {}'.format( row, col)) new.link(neighbor)
def _rotate_cell_neighbors(new_cell: Cell, old_cell: Cell, grid: Grid) -> None: for link in old_cell.links: row, column = Rotator._rotated_coordinates(link, grid) neighbor = grid.cell_at(row, column) if neighbor is None: raise IndexError("Cell not found at row {} column {}".format( row, column)) new_cell.link(neighbor)
def test_links_listing() -> None: a_cell = Cell(1, 1) another_cell = Cell(1, 2) yet_another_cell = Cell(2, 1) a_cell.link(another_cell) a_cell.link(yet_another_cell) assert set(a_cell.links).intersection([another_cell, yet_another_cell]) == set(a_cell.links) assert another_cell.links == [a_cell] assert yet_another_cell.links == [a_cell]
def test_distances() -> None: a_cell = Cell(0, 0) another_cell = Cell(0, 1) yet_another_cell = Cell(0, 2) a_cell.east = another_cell a_cell.link(another_cell) another_cell.east = yet_another_cell another_cell.link(yet_another_cell) distances = a_cell.distances assert set(distances.cells) == {yet_another_cell, another_cell, a_cell} assert distances[a_cell] == 0 assert distances[another_cell] == 1 assert distances[yet_another_cell] == 2
def test_linking() -> None: a_cell = Cell(1, 1) another_cell = Cell(1, 2) yet_another_cell = Cell(2, 1) assert a_cell.linked_to(another_cell) is False assert another_cell.linked_to(a_cell) is False assert a_cell.linked_to(yet_another_cell) is False assert another_cell.linked_to(yet_another_cell) is False a_cell.link(another_cell) assert a_cell.linked_to(another_cell) is True assert another_cell.linked_to(a_cell) is True assert a_cell.linked_to(yet_another_cell) is False assert another_cell.linked_to(yet_another_cell) is False