def test_undirected_edge_get(self): """ Get an attribute of an undirected edge """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1), attrs={'weight': 5}) self.assertEqual(e01.get('weight'), 5) self.assertIsNone(e01.get('notthere'))
def test_undirected_edge_attrs(self): """ Get an undirected edge's attrs property """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1), {'weight': 5}) self.assertEqual(e01.attrs, {'weight': 5}) with self.assertRaises(AttributeError): e01.attrs = {'key': 'value'}
def test_undirected_edge_vertices(self): """ Get an undirected edge's vertices property """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1)) self.assertEqual(e01.vertices, frozenset([v0, v1])) with self.assertRaises(AttributeError): e01.vertices = frozenset()
def test_undirected_edge_is_self_edge(self): """ Get an undirected edge's is_self_edge property """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e00 = UndirectedEdge((v0, v0)) e01 = UndirectedEdge((v0, v1)) self.assertTrue(e00.is_self_edge) self.assertFalse(e01.is_self_edge) with self.assertRaises(AttributeError): e00.is_self_edge = False
def test_undirected_edge_del_attr(self): """ Delete an attribute of an undirected edge """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1), attrs={'weight': 5, 0: 1}) e01.del_attr('weight') self.assertEqual(e01.attrs, {0: 1}) e01.del_attr(0) self.assertEqual(e01.attrs, {})
def test_undirected_edge_set(self): """ Set an attribute of an undirected edge """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1)) e01.set('weight', 5) self.assertEqual(e01.attrs, {'weight': 5}) e01.set(0, 1) self.assertEqual(e01.attrs, {'weight': 5, 0: 1})
def test_undirected_edge_has_attr(self): """ Check if an undirected edge has a particular attribute """ v0 = UndirectedVertex(val='v0') v1 = UndirectedVertex(val='v1') e01 = UndirectedEdge((v0, v1), attrs={'weight': 5, 0: 1}) self.assertTrue(e01.has_attr('weight')) self.assertFalse(e01.has_attr('length')) e01.del_attr('weight') self.assertFalse(e01.has_attr('weight'))