def test_get_all_v(self): graph = DiGraph() for i in range(10): graph.add_node(i) for i in range(9): graph.add_edge(i, i + 1, i * 2 + 1) l = [] for vertex in graph.Nodes.values(): l.append(vertex) for vertex in l: self.assertIn(vertex, graph.get_all_v()) graph.remove_node(3) self.assertNotIn(3, graph.get_all_v())
def test_remove_node(self): graph = DiGraph() for i in range(10): graph.add_node(i) for i in range(9): graph.add_edge(i, i + 1, i * 2 + 1) self.assertTrue(graph.remove_node(0)) self.assertEqual(graph.e_size(), 8) self.assertEqual(graph.v_size(), 9) self.assertFalse(0 in graph.Nodes.keys()) self.assertTrue(8 in graph.Nodes.keys()) self.assertFalse(graph.remove_node(0)) self.assertFalse(graph.remove_node(20)) self.assertEqual(graph.v_size(), 9)
def test_get_mc(self): graph = DiGraph() for i in range(10): graph.add_node(i) for i in range(9): graph.add_edge(i, i + 1, i * 2 + 1) self.assertEqual(graph.get_mc(), 19) graph.remove_edge(0, 1) self.assertEqual(graph.get_mc(), 20) graph.add_edge(0, 1, 1) self.assertEqual(graph.get_mc(), 21) graph.add_edge(0, 1, 1) self.assertEqual(graph.get_mc(), 21) graph.remove_node(0) self.assertEqual(graph.get_mc(), 22) graph.remove_node(0) self.assertEqual(graph.get_mc(), 22) graph.add_node(0) self.assertEqual(graph.get_mc(), 23) graph.add_node(0) self.assertEqual(graph.get_mc(), 23)