当前位置: 首页>>代码示例>>Python>>正文


Python Graph.path_between方法代码示例

本文整理汇总了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"))
开发者ID:Hristiyan-Andreev,项目名称:HackBuglaria,代码行数:11,代码来源:testGraph.py

示例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)
开发者ID:Fusl,项目名称:Hack-Bulgaria-Programming-101,代码行数:46,代码来源:Graph_test.py


注:本文中的Graph.Graph.path_between方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。