Esempio n. 1
0
    def test_add_all_edges(self):
        # Adds an edge to edge-less graph
        v, w, e = self.v, self.w, self.e
        g = Graph([v, w], [])
        g.add_all_edges()
        eq_(g.edges(), [e])

        # Adds edges between all pairs of vertices in edge-less graph
        x = Vertex('x')
        e2 = Edge(v, x)
        e3 = Edge(w, x)
        g = Graph([v, w, x], [])
        g.add_all_edges()
        eq_(g.edges(), [e, e2, e3])
Esempio n. 2
0
    def test_is_connected(self):
        # Returns False for an empty graph
        v, w = self.v, self.w
        g = Graph([v, w], [])
        eq_(g.is_connected(), False)

        # Returns True for a complete graph
        g.add_all_edges()
        eq_(g.is_connected(), True)

        # Returns False when a new vertex is added
        x = Vertex('x')
        g.add_vertex(x)
        eq_(g.is_connected(), False)

        # Returns True when edge is added to connect it
        e2 = Edge(w, x)
        g.add_edge(e2)
        eq_(g.is_connected(), True)