def test_get_weight(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) vertex.add_neighbor(data='b') self.assertEqual(vertex.get_weight('b'), 1) vertex.add_neighbor(data='b', weight=5) self.assertEqual(vertex.get_weight('b'), 5)
def test_add(self): vertex = Vertex(data='a') self.assertEqual(vertex.add(neighbors=None), None) self.assertEqual(set(list(vertex.get_neighbors())), set([])) data = [ ('b', 3), ('c', 7), ('d'), tuple(['e']) ] vertex.add(neighbors=data) self.assertEqual(set(list(vertex.get_neighbors())), set(['b', 'c', 'd', 'e'])) self.assertEqual(vertex.get_weight('b'), 3) self.assertEqual(vertex.get_weight('c'), 7) self.assertEqual(vertex.get_weight('d'), 1) self.assertEqual(vertex.get_weight('e'), 1)
def test_get_weight_keyerror(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) vertex.add_neighbor(data='b') with self.assertRaises(KeyError) as error: self.assertEqual(vertex.get_weight('c'), None)