Ejemplo n.º 1
0
def test_no_icebergs():
    """Test that with no icebergs, a direct route is taken."""
    start = Point2D(4, 4)
    end = Point2D(12, 80)
    icebergs = ()
    assert get_shortest_route(start=start, end=end, icebergs=icebergs) == [
        Point2D(4, 4),
        Point2D(12, 80),
    ]
Ejemplo n.º 2
0
def test_route_on_iceberg_point():
    """Test when the shortest route touches one point of an iceberg."""
    start = Point2D(0, 0)
    end = Point2D(5, 5)

    icebergs = (Polygon(Point2D(1, 2), Point2D(1, 3), Point2D(5, 2)), )
    assert get_shortest_route(start=start, end=end, icebergs=icebergs) == [
        Point2D(0, 0),
        Point2D(1, 3),
        Point2D(5, 5),
    ]
Ejemplo n.º 3
0
def test_route_on_iceberg_side():
    """Test when the shortest route goes alongside an iceberg."""
    start = Point2D(4, 4)
    end = Point2D(12, 80)

    icebergs = (Polygon(Point2D(4, 7), Point2D(4, 8), Point2D(100, 8),
                        Point2D(100, 7)), )
    assert get_shortest_route(start=start, end=end, icebergs=icebergs) == [
        Point2D(4, 4),
        Point2D(4, 8),
        Point2D(12, 80),
    ]
Ejemplo n.º 4
0
def test_irrelevant_icebergs():
    """Test that if the direct route is not interrupted, it is used."""
    start = Point2D(4, 4)
    end = Point2D(12, 80)
    icebergs = (
        Polygon(Point2D(0, 0), Point2D(1, 1), Point2D(0, 2)),
        Polygon(Point2D(11, 20), Point2D(15, 50), Point2D(15, 20)),
    )
    assert get_shortest_route(start=start, end=end, icebergs=icebergs) == [
        Point2D(4, 4),
        Point2D(12, 80),
    ]
Ejemplo n.º 5
0
def test_complex_route():
    start = Point2D(5, 0)
    end = Point2D(5, 5)

    icebergs = (
        Polygon(Point2D(4, 1), Point2D(8, 1), Point2D(8, 2), Point2D(4, 2)),
        Polygon(Point2D(6, 3), Point2D(6, 4), Point2D(2, 4), Point2D(2, 3)),
    )
    assert get_shortest_route(start=start, end=end, icebergs=icebergs) == [
        Point2D(5, 0),
        Point2D(4, 1),
        Point2D(4, 2),
        Point2D(6, 3),
        Point2D(6, 4),
        Point2D(5, 5),
    ]