Ejemplo n.º 1
0
    def test_undirected_vertex_has_self_edge(self):
        """ Get an undirected vertex's has_self_edge property """
        v0 = UndirectedVertex(val='v0')
        v1 = UndirectedVertex(val='v1')
        v2 = UndirectedVertex(val='v2')
        e00 = UndirectedEdge((v0, v0))
        e01 = UndirectedEdge((v0, v1))
        e11 = UndirectedEdge((v1, v1))
        e02 = UndirectedEdge((v0, v2))
        v0.add_edge(e00)
        v0.add_edge(e01)
        v1.add_edge(e01)
        v0.add_edge(e02)
        v2.add_edge(e02)

        self.assertTrue(v0.has_self_edge)
        self.assertFalse(v1.has_self_edge)
        self.assertFalse(v2.has_self_edge)
        with self.assertRaises(AttributeError):
            v0.has_self_edge = True

        v1.add_edge(e11)
        v0.remove_edge(e00)

        self.assertFalse(v0.has_self_edge)
        self.assertTrue(v1.has_self_edge)
        self.assertFalse(v2.has_self_edge)
Ejemplo n.º 2
0
    def test_undirected_vertex_remove_edge(self):
        """ Remove an edge from an undirected vertex """
        v0 = UndirectedVertex(val='v0')
        v1 = UndirectedVertex(val='v1')
        v2 = UndirectedVertex(val='v2')
        e01 = UndirectedEdge((v0, v1))
        e10 = UndirectedEdge((v1, v0))
        e02 = UndirectedEdge((v0, v2))
        v0.add_edge(e01)
        v0.add_edge(e02)

        v0.remove_edge(e01)

        self.assertFalse(e01 in v0)
        self.assertFalse(e10 in v0)
        self.assertTrue(e02 in v0)

        v0.remove_edge(e02)

        self.assertFalse(e01 in v0)
        self.assertFalse(e10 in v0)
        self.assertFalse(e02 in v0)