Ejemplo n.º 1
0
 def test_WeakVerticesThreeStrongVertices(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2])
     graph.AddEdge(0, 1)
     graph.AddEdge(1, 2)
     graph.AddEdge(2, 0)
     result = graph.WeakVertices()
     self.assertTrue(result == [], result)
Ejemplo n.º 2
0
 def test_WeakVerticesFiveVerticesWithTriangle(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2, 3, 4])
     graph.AddEdge(1, 2)
     graph.AddEdge(2, 4)
     graph.AddEdge(4, 1)
     result = graph.WeakVertices()
     self.assertTrue(result == [graph.vertex[0], graph.vertex[3]], result)
Ejemplo n.º 3
0
 def test_BreadthFirstSearchWithCycle(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2])
     graph.AddEdge(0, 1)
     graph.AddEdge(1, 1)
     graph.AddEdge(1, 2)
     result = graph.BreadthFirstSearch(0, 2)
     self.assertTrue(
         result == [graph.vertex[0], graph.vertex[1], graph.vertex[2]],
         result)
Ejemplo n.º 4
0
 def test_WeakVerticesFiveVerticesWithTwoTriangles(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2, 3, 4])
     graph.AddEdge(0, 1)
     graph.AddEdge(1, 2)
     graph.AddEdge(2, 0)
     graph.AddEdge(0, 3)
     graph.AddEdge(0, 4)
     graph.AddEdge(3, 4)
     result = graph.WeakVertices()
     self.assertTrue(result == [], result)
Ejemplo n.º 5
0
 def test_WeakVerticesSixVerticesWithOneWeekVertex(self):
     graph = SimpleGraph(6)
     self.addVertexes(graph, [0, 1, 2, 3, 4, 5])
     graph.AddEdge(0, 1)
     graph.AddEdge(1, 2)
     graph.AddEdge(2, 0)
     graph.AddEdge(0, 3)
     graph.AddEdge(0, 4)
     graph.AddEdge(3, 4)
     graph.AddEdge(1, 5)
     result = graph.WeakVertices()
     self.assertTrue(result == [graph.vertex[5]], result)
Ejemplo n.º 6
0
 def test_BreadthFirstSearchWithDifferentPaths(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2, 3, 4])
     graph.AddEdge(0, 1)
     graph.AddEdge(1, 2)
     graph.AddEdge(2, 3)
     graph.AddEdge(3, 4)
     graph.AddEdge(4, 0)
     result = graph.BreadthFirstSearch(0, 2)
     self.assertTrue(
         result == [graph.vertex[0], graph.vertex[1], graph.vertex[2]],
         result)
Ejemplo n.º 7
0
 def test_RemoveVertex(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2])
     graph.AddEdge(0, 1)
     graph.AddEdge(0, 2)
     graph.RemoveVertex(0)
     self.checkVertexAdjacency(graph, 0, [0] * 5)
Ejemplo n.º 8
0
 def test_RemoveEdge(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1])
     graph.AddEdge(0, 1)
     self.checkEdge(graph, 0, 1, 1)
     graph.RemoveEdge(1, 0)
     self.checkEdge(graph, 0, 1, 0)
Ejemplo n.º 9
0
 def test_DepthFirstSearchThreeVertexWithEdge(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2])
     graph.AddEdge(0, 1)
     graph.AddEdge(0, 2)
     result = graph.DepthFirstSearch(0, 2)
     self.assertTrue(result == [graph.vertex[0], graph.vertex[2]], result)
Ejemplo n.º 10
0
 def test_DepthFirstSearchSingleVertexWithEdge(self):
     graph = SimpleGraph(5)
     graph.AddVertex(0)
     graph.AddEdge(0, 0)
     result = graph.DepthFirstSearch(0, 0)
     self.assertTrue(result == [graph.vertex[0], graph.vertex[0]], result)
Ejemplo n.º 11
0
 def test_BreadthFirstSearchThreeVertexWithoutEdge(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1, 2])
     graph.AddEdge(0, 1)
     result = graph.BreadthFirstSearch(0, 2)
     self.assertTrue(result == [], result)
Ejemplo n.º 12
0
 def test_BreadthFirstSearchTwoVertexWithEdge(self):
     graph = SimpleGraph(5)
     self.addVertexes(graph, [0, 1])
     graph.AddEdge(0, 1)
     result = graph.BreadthFirstSearch(0, 1)
     self.assertTrue(result == [graph.vertex[0], graph.vertex[1]], result)