def to_coordinate_list(self, separator: str = _DEFAULT_SEPARATOR ) -> List[Coordinate]: return [ Coordinate.from_point(numbers[0], numbers[1]) for numbers in self.to_number_lists(separator) ]
def test_neighbors(): coord = Coordinate.from_point(x=2, y=2) assert coord.get_neighbor_left().x == 1 assert coord.get_neighbor_left().y == 2 assert coord.get_neighbor_right().x == 3 assert coord.get_neighbor_right().y == 2 assert coord.get_neighbor_above().x == 2 assert coord.get_neighbor_above().y == 1 assert coord.get_neighbor_below().x == 2 assert coord.get_neighbor_below().y == 3 assert coord.get_neighbor_left_above().x == 1 assert coord.get_neighbor_left_above().y == 1 assert coord.get_neighbor_right_above().x == 3 assert coord.get_neighbor_right_above().y == 1 assert coord.get_neighbor_left_below().x == 1 assert coord.get_neighbor_left_below().y == 3 assert coord.get_neighbor_right_below().x == 3 assert coord.get_neighbor_right_below().y == 3 non_diagonal_neighbors = [ coord.get_neighbor_left(), coord.get_neighbor_right(), coord.get_neighbor_above(), coord.get_neighbor_below() ] assert coord.get_neighbors( include_diagonal=False) == non_diagonal_neighbors assert coord.get_neighbors( include_diagonal=True) == non_diagonal_neighbors + [ coord.get_neighbor_left_above(), coord.get_neighbor_right_above(), coord.get_neighbor_left_below(), coord.get_neighbor_right_below() ]
def test_from_point(): coord = Coordinate.from_point(x=1, y=2) assert coord.row == 2 assert coord.column == 1 assert coord.y == 2 assert coord.x == 1
def test_to_coordinate_list(): assert Parser.from_lines(["1 2", "3 4"]).to_coordinate_list() == \ [Coordinate.from_point(1, 2), Coordinate.from_point(3, 4)] assert Parser.from_lines(["1, 2", "3, 4"]).to_coordinate_list(separator=",") == \ [Coordinate.from_point(1, 2), Coordinate.from_point(3, 4)]