Ejemplo n.º 1
0
    def test_add_node_with_connnections__base(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, b, c], e: [c], f: []}

        graph = Graph(g)

        h = Node('H', Vector2(100, 100))

        graph.add_node_with_connnections(h, {
            a: EdgeDirection.FROM,
            b: EdgeDirection.TO,
            c: EdgeDirection.TWOWAY
        })

        assert h in graph.nodes

        assert graph.edge_between(a, h) is not None
        assert graph.edge_between(h, a) is None
        assert graph.edge_between(b, h) is None
        assert graph.edge_between(h, b) is not None
        assert graph.edge_between(c, h) is not None
        assert graph.edge_between(h, c) is not None
Ejemplo n.º 2
0
    def test_disable_edges(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, b, c], e: [c, f], f: []}

        graph = Graph(g)
        graph.disable_edges(graph.edge_between(d, c), "BLOCK")
        assert graph.edge_between(d, c).disablers() == {"BLOCK"}
Ejemplo n.º 3
0
    def test_edges_to_node(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, c], e: [c, f], f: []}

        graph = Graph(g)

        assert set(graph.edges_to_node(c)) == {
            graph.edge_between(b, c),
            graph.edge_between(d, c),
            graph.edge_between(e, c),
            graph.edge_between(c, b),
            graph.edge_between(c, d),
            graph.edge_between(c, e)
        }
Ejemplo n.º 4
0
    def test__astar_with_disablers(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, b, c], e: [c, f], f: []}

        graph = Graph(g)
        graph.disable_edges(graph.edge_between(d, c), "BLOCK")

        path = graph.astar(a, e)

        assert path.path == [a, d, b, c, e]
Ejemplo n.º 5
0
    def test_copy__base(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, b, c], e: [c], f: []}

        graph = Graph(g)

        copy = graph.copy()

        assert len(copy.nodes) == len(graph.nodes)
        assert len(copy.edges) == len(graph.edges)
        assert (edge.disablers() == graph.edge_between(edge.start,
                                                       edge.end).disablers()
                for edge in copy.edges)
Ejemplo n.º 6
0
    def test__edge_by_id(self):
        a = Node(name='A', pos=Vector2(0, 0))
        b = Node(name='B', pos=Vector2(3, 3))
        c = Node(name='C', pos=Vector2(2, 0))
        d = Node(name='D', pos=Vector2(2, 1))
        e = Node(name='E', pos=Vector2(3, 4))
        f = Node(name='F', pos=Vector2(5, 5))

        g = {a: [d], b: [c], c: [b, d, e], d: [a, b, c], e: [c], f: []}

        graph = Graph(g)

        edge = graph.edge_between(a, d)

        self.assertIsNotNone(edge,
                             "Edge was returned none when expected value")

        edge_ret = graph.edges_by_id([edge.id])[0]

        self.assertEqual(
            edge, edge_ret,
            f"returned edge {edge_ret} [{edge_ret.id}] does not match {edge} [{edge.id}]"
        )