Exemplo n.º 1
0
    def test_wait(self):
        waitend = 100
        tz = Timezone()
        tz.add_period(TimezonePeriod(0, 100000, 0))
        w = Wait(waitend, tz)
        assert w.end == waitend
        assert w.timezone.soul == tz.soul
        assert w.to_xml() == "<Wait end='100' />"

        s = State(1, 0)
        sprime = w.walk(s, WalkOptions())
        assert sprime.time == 100
        assert sprime.weight == 100

        s = State(1, 150)
        sprime = w.walk_back(s, WalkOptions())
        assert sprime.time == 100
        assert sprime.weight == 50

        s = State(1, 86400)
        sprime = w.walk(s, WalkOptions())
        assert sprime.time == 86500
        assert sprime.weight == 100

        w.destroy()

        tz = Timezone()
        tz.add_period(TimezonePeriod(0, 100000, -20))
        w = Wait(100, tz)
        assert w.end == 100
        assert w.timezone.soul == tz.soul
        s = State(1, 86400)
        sprime = w.walk(s, WalkOptions())
        assert sprime.weight == 120
Exemplo n.º 2
0
    def test_hello_world(self):
        g = Graph()

        g.add_vertex("Seattle")
        g.add_vertex("Portland")

        g.add_edge("Seattle", "Portland", Street("I-5 south", 5000))
        g.add_edge("Portland", "Seattle", Street("I-5 north", 5500))

        spt = g.shortest_path_tree("Seattle", "Portland",
                                   State(g.numagencies, 0), WalkOptions())

        assert spt.get_vertex(
            "Seattle").outgoing[0].payload.name == "I-5 south"

        g.add_vertex("Portland-busstop")
        g.add_vertex("Seattle-busstop")

        g.add_edge("Seattle", "Seattle-busstop", Link())
        g.add_edge("Seattle-busstop", "Seattle", Link())
        g.add_edge("Portland", "Portland-busstop", Link())
        g.add_edge("Portland-busstop", "Portland", Link())

        spt = g.shortest_path_tree("Seattle", "Seattle-busstop",
                                   State(g.numagencies, 0), WalkOptions())
        assert spt.get_vertex(
            "Seattle-busstop").incoming[0].payload.__class__ == Link
        spt.destroy()

        spt = g.shortest_path_tree("Seattle-busstop", "Portland",
                                   State(g.numagencies, 0), WalkOptions())
        assert spt.get_vertex(
            "Portland").incoming[0].payload.__class__ == Street
        spt.destroy()

        sc = ServiceCalendar()
        sc.add_period(0, 86400, ["WKDY", "SAT"])
        tz = Timezone()
        tz.add_period(TimezonePeriod(0, 86400, 0))

        g.add_vertex("Portland-busstop-onbus")
        g.add_vertex("Seattle-busstop-onbus")

        tb = TripBoard("WKDY", sc, tz, 0)
        tb.add_boarding("A", 10, 0)
        tb.add_boarding("B", 15, 0)
        tb.add_boarding("C", 400, 0)

        cr = Crossing()

        al = TripAlight("WKDY", sc, tz, 0)
        al.add_alighting("A", 10 + 20, 0)
        al.add_alighting("B", 15 + 20, 0)
        al.add_alighting("C", 400 + 20, 0)

        g.add_edge("Seattle-busstop", "Seattle-busstop-onbus", tb)
        g.add_edge("Seattle-busstop-onbus", "Portland-busstop-onbus", cr)
        g.add_edge("Portland-busstop-onbus", "Portland-busstop", al)

        spt = g.shortest_path_tree("Seattle", "Portland",
                                   State(g.numagencies, 0), WalkOptions())

        assert spt.get_vertex("Portland").incoming[0].from_v.incoming[
            0].from_v.incoming[0].from_v.incoming[0].from_v.incoming[
                0].from_v.label == "Seattle"

        spt = g.shortest_path_tree("Seattle", "Portland",
                                   State(g.numagencies, 0), WalkOptions())
        vertices, edges = spt.path("Portland")

        assert [v.label for v in vertices] == [
            'Seattle', 'Seattle-busstop', "Seattle-busstop-onbus",
            "Portland-busstop-onbus", 'Portland-busstop', 'Portland'
        ]
        assert [e.payload.__class__ for e in edges
                ] == [Link, TripBoard, Crossing, TripAlight, Link]

        spt.destroy()
        g.destroy()