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


Python Edge.adjacent方法代码示例

本文整理汇总了Python中edge.Edge.adjacent方法的典型用法代码示例。如果您正苦于以下问题:Python Edge.adjacent方法的具体用法?Python Edge.adjacent怎么用?Python Edge.adjacent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edge.Edge的用法示例。


在下文中一共展示了Edge.adjacent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestEdge

# 需要导入模块: from edge import Edge [as 别名]
# 或者: from edge.Edge import adjacent [as 别名]
class TestEdge(unittest.TestCase):


    def setUp(self):
        self.v1 = Vertex(1)
        self.v2 = Vertex(2)
        self.x = Vertex('x')
        self.another_x = Vertex('x')
        self.e12 = Edge(self.v1, self.v2)
        self.e21 = Edge(self.v2, self.v1)


    def test_a_edge_cant_have_autoloop(self):
        """Uma aresta não possui autoloop"""
        with self.assertRaises(Exception):
            Edge(self.x, self.another_x)

    def test_two_edges_are_equal_independent_of_vertices_order(self):
        """Duas arestas são iguais, independentemente da ordem dos vértice"""
        self.assertEqual(self.e12, self.e21)


    def test_incide(self):
        """Um Vértice incide numa aresta, se ele é um de seus componentes"""
        self.assertTrue(self.e12.incide(self.v1))
        self.assertTrue(self.e21.incide(self.v1))
        self.assertTrue(self.e12.incide(self.v2))
        self.assertTrue(self.e21.incide(self.v2))
        self.assertFalse(self.e12.incide(self.x))
        self.assertFalse(self.e21.incide(self.x))
        self.assertTrue(self.x not in self.e21)
        self.assertTrue(self.v1 in self.e12)
        self.assertTrue(self.v1 in self.e21)
        self.assertTrue(self.v2 in self.e12)
        self.assertTrue(self.v2 in self.e12)

    def test_adjacent(self):
        """Os vértices que são pontas das arestas são adjacentes"""
        self.assertTrue(self.e12.adjacent(self.v1), self.v2)
        self.assertTrue(self.e12.adjacent(self.v2), self.v1)
        self.assertTrue(self.e21.adjacent(self.v1), self.v2)
        self.assertTrue(self.e21.adjacent(self.v2), self.v1)

    def test_adjacent_error(self):
        """Se um vértice não pertence à aresta, adjacent retorna um erro"""
        with self.assertRaises(Exception):
            self.e12.adjacent(self.x)

    def test_edge_iteration(self):
        """É possível iterar sobre os vértices de uma aresta"""
        i = 0
        for u in self.e12:
            if i == 0:
               self.assertTrue(u == self.v1)
            if i == 1:
               self.assertTrue(u == self.v2)
            i = i + 1
开发者ID:everaldo,项目名称:aed_ii,代码行数:59,代码来源:test_edge.py


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