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_remove_neighbor(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) vertex.add_neighbor(data='b') self.assertEqual(set(list(vertex.adjacent.keys())), set(['b'])) self.assertEqual(vertex.adjacent.get('b'), 1) self.assertEqual(vertex.remove_neighbor(data='b'), True)
def test_remove_neighbor_key_error(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) vertex.add_neighbor(data='b') self.assertEqual(set(list(vertex.adjacent.keys())), set(['b'])) self.assertEqual(vertex.adjacent.get('b'), 1) with self.assertRaises(KeyError) as error: self.assertEqual(vertex.remove_neighbor(data='invalid_key'), False)
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)
def test_get_neighbor(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) vertex.add_neighbor(data='b') self.assertEqual(vertex.get_neighbors(), ['b'])
def test_add_neighbor_negative_weight(self): vertex = Vertex(data='a') self.assertEqual(set(list(vertex.adjacent.keys())), set([])) with self.assertRaises(TypeError) as error: vertex.add_neighbor(data='b', weight=-5)