def test_add_empty_tuple(self): vertex = Vertex(data='a') self.assertEqual(vertex.add(neighbors=None), None) self.assertEqual(set(list(vertex.get_neighbors())), set([])) data = [ tuple() ] self.assertEqual(vertex.add(neighbors=data), None)
def test_add_tuple_not_int(self): vertex = Vertex(data='a') self.assertEqual(vertex.add(neighbors=None), None) self.assertEqual(set(list(vertex.get_neighbors())), set([])) data = [ ('b', 'invalid weight'), ] with self.assertRaises(TypeError) as error: vertex.add(neighbors=data)
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_add_neighbors_not_tuple(self): vertex = Vertex(data='a') with self.assertRaises(TypeError) as error: self.assertIsNone(vertex.add(neighbors=['invalid_data']))