本文整理匯總了Python中edge.Edge.incide方法的典型用法代碼示例。如果您正苦於以下問題:Python Edge.incide方法的具體用法?Python Edge.incide怎麽用?Python Edge.incide使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類edge.Edge
的用法示例。
在下文中一共展示了Edge.incide方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestEdge
# 需要導入模塊: from edge import Edge [as 別名]
# 或者: from edge.Edge import incide [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