def test_distance_between_sao_paulo_and_rio_de_janeiro_is_357_km():
    rio_de_janeiro = Point.of(-22.9028, 43.2075)
    sao_paulo = Point.of(-23.5475, 46.6361)

    assert round(
        great_circle_distance(rio_de_janeiro, sao_paulo).kilometers,
        4) == round(Decimal(357.5967), 4)
def nearest_customer(
    office_coordinate: Point,
    max_distance_from_office: Distance,
    customer_coordinates: List[CustomerCoordinate],
) -> List[Customer]:
    return sorted(
        [
            each.customer
            for each in customer_coordinates if great_circle_distance(
                office_coordinate, each.coordinate) <= max_distance_from_office
        ],
        key=attrgetter("user_id"),
    )
Ejemplo n.º 3
0
def test_returns_none_customer(customer, points, quantity):
    office_point, customer_point = points

    # the max distance is half the distance between the two points
    max_distance_from_office = Distance.of(
        great_circle_distance(office_point, customer_point).kilometers / 2)

    customer_coordinates = [
        CustomerCoordinate(customer, customer_point) for _ in range(quantity)
    ]

    customers = nearest_customer(
        office_coordinate=office_point,
        max_distance_from_office=max_distance_from_office,
        customer_coordinates=customer_coordinates,
    )

    assert len(customers) == 0
def test_inverse_of_the_distances_are_equal(point_a, point_b):
    assert great_circle_distance(point_a, point_b) == great_circle_distance(
        point_b, point_a)
def test_returns_instance_of_point(a, b):
    distance = great_circle_distance(a, b)

    assert isinstance(distance, Distance)
def test_distance_is_zero_point_is_equal(point):
    assert great_circle_distance(point, point) == Distance.of(0)