Example #1
0
 def test_add_vertex(self):
     graph = Graph()
     lst = ["A", "B", "C", "D"]
     [graph.addVertex(vert) for vert in lst]
     assert len(graph.vertList) is 4
     assert graph.numVertices is 4
     assert graph.getVertex('A').getId() is 'A'
     assert graph.getVertex('B').getId() is 'B'
Example #2
0
    def create_graph(graph_data):
        is_graph = graph_data[0] is 'G'

        graph = Graph()

        for vertex in graph_data[1].split(','):
            graph.addVertex(vertex)

        counter = 0

        for word in graph_data[2:]:
            counter += 1
            if is_graph:
                graph.addEdge(word[3], word[1], word[5:].replace(')', ''))
                graph.addEdge(word[1], word[3], word[5:].replace(')', ''))
            else:
                graph.addEdge(word[1], word[3], word[5:].replace(')', ''))

        return graph, counter
Example #3
0
    def test_add_vertex(self):
        g = Graph()
        g.addVertex(1)
        g.addVertex(2)

        self.assertEqual(2, len(g.getVertices()))
Example #4
0
 def test_add_edge(self):
     graph = Graph()
     lst = ["A", "B", "C", "D"]
     [graph.addVertex(vert) for vert in lst]
     graph.addEdge('A', 'B')