當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。