本文整理汇总了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