本文整理汇总了Python中Graph.Graph.path_between方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.path_between方法的具体用法?Python Graph.path_between怎么用?Python Graph.path_between使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.path_between方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_path_between
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import path_between [as 别名]
def test_path_between(self):
graph1 = Graph("Graphec")
graph1.add_edge("A", "B")
graph1.add_edge("A", "C")
graph1.add_edge("C", "D")
graph1.add_edge("D", "E")
graph1.add_edge("D", "F")
graph1.add_edge("P", "O")
self.assertFalse(graph1.path_between("A", "O"))
示例2: GraphTests
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import path_between [as 别名]
class GraphTests(unittest.TestCase):
def setUp(self):
self.graph = Graph()
self.node1 = Node("N1")
self.node2 = Node("N2")
self.node3 = Node("N3")
def test_init(self):
self.assertEqual([], self.graph.nodes)
def test_add_edge(self):
self.graph.add_edge(self.node1, self.node2)
self.assertEqual([], self.graph.get_neighbors_for(self.node2))
self.assertEqual([self.node2],
self.graph.get_neighbors_for(self.node1))
def test_add_edge_no_nodes(self):
self.graph.add_edge(self.node1, self.node2)
self.assertEqual([self.node1, self.node2], self.graph.nodes)
def test_get_neighbors_for(self):
self.graph.add_edge(self.node1, self.node2)
self.graph.add_edge(self.node1, self.node3)
self.assertEqual([self.node1, self.node2, self.node3],
self.graph.nodes)
def test_path_between(self):
self.graph.add_edge(self.node1, self.node2)
self.graph.add_edge(self.node2, self.node3)
self.assertTrue(self.graph.path_between(self.node1, self.node3))
self.assertFalse(self.graph.path_between(self.node2, self.node1))
def test_path_between_cyles(self):
self.graph.add_edge(self.node1, self.node2)
self.graph.add_edge(self.node2, self.node3)
self.graph.add_edge(self.node3, self.node1)
self.assertTrue(self.graph.path_between(self.node2, self.node1))
def test_str(self):
self.graph.add_edge(self.node1, self.node2)
self.graph.add_edge(self.node2, self.node3)
self.graph.add_edge(self.node3, self.node1)
print(self.graph)