Esempio n. 1
0
 def test_get_mc(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_edge(1, 1, 3)
     g.add_edge(1, 2, 4)
     g.add_edge(1, 6, -8)
     g.add_edge(2, 1, 7)
     g.add_edge(2, 1, 7)
     g.add_edge(4, 1, 4)
     g.add_edge(32, 1, 4)
     g.add_edge(5, 1, 4)
     g.add_edge(5, 1, 3)
     g.add_edge(3, 1, 3)
     g.remove_node(3)
     g.add_edge(6, 1, 3)
     g.remove_edge(6, 1)
     self.assertEqual(g.get_mc(), 15)
Esempio n. 2
0
 def test_remove_edge(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     for i in range(4):
         g.add_edge(i, i + 1, 5)
     self.assertFalse(g.remove_edge(1, 6))
     self.assertFalse(g.remove_edge(7, 6))
     g.add_edge(0, 2, 2)
     g.add_edge(0, 3, 2)
     g.add_edge(0, 4, 2)
     g.add_edge(0, 5, 2)
     g.remove_edge(0, 1)
     g.remove_edge(0, 4)
     list = [2, 3, 5]
     sec_list = []
     for key in g.all_out_edges_of_node(0).keys():
         sec_list.append(key)
     self.assertListEqual(sec_list, list)
Esempio n. 3
0
 def test_all_in_edges_of_node(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_edge(1, 1, 3)
     g.add_edge(1, 2, 4)
     g.add_edge(1, 6, -8)
     g.add_edge(2, 1, 7)
     g.add_edge(2, 1, 7)
     g.add_edge(4, 1, 4)
     g.add_edge(32, 1, 4)
     g.add_edge(5, 1, 4)
     g.add_edge(5, 1, 3)
     g.add_edge(3, 1, 3)
     g.remove_node(3)
     g.add_edge(6, 1, 3)
     g.remove_edge(6, 1)
     self.assertIsNone(g.all_in_edges_of_node(22), None)
     dict = g.all_in_edges_of_node(1)
     self.assertEqual(len(dict), 3)
Esempio n. 4
0
 def test_connected_component(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_edge(0, 1, 5)
     g.add_edge(0, 2, 3)
     g.add_edge(0, 1, 5)
     g.add_edge(1, 6, 12.1)
     g.add_edge(2, 3, 2)
     g.add_edge(2, 5, 8)
     g.add_edge(3, 4, 1)
     g.add_edge(4, 5, 4)
     g.add_edge(5, 6, 7)
     g.add_edge(3, 0, 1)
     g.add_edge(1, 3, 5)
     graph = GraphAlgo(g)
     self.assertListEqual(graph.connected_component(0), [0, 1, 2, 3])
     g.remove_edge(1, 3)
     self.assertListEqual(graph.connected_component(0), [0, 2, 3])
     g.add_edge(5, 0, 8)
     self.assertListEqual(graph.connected_component(0), [0, 2, 3, 4, 5])
Esempio n. 5
0
 def test_all_out_edges_of_node(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_edge(1, 1, 3)
     g.add_edge(1, 2, 4)
     g.add_edge(1, 6, -8)
     g.add_edge(1, 2, 7)
     g.add_edge(1, 3, 7)
     g.add_edge(1, 4, 4)
     g.add_edge(1, 18, 4)
     g.remove_node(3)
     g.add_edge(1, 6, 3)
     g.remove_edge(1, 6)
     g.add_edge(1, 5, 3)
     self.assertIsNone(g.all_out_edges_of_node(22), None)
     dict = g.all_out_edges_of_node(1)
     list = []
     for key in dict.keys():
         list.append(key)
     sec_list = [2, 4, 5]
     self.assertListEqual(list, sec_list)
Esempio n. 6
0
 def test_get_edge(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_edge(1, 1, 3)
     g.add_edge(1, 2, 4)
     g.add_edge(1, 6, -8)
     g.add_edge(2, 1, 7)
     g.add_edge(2, 1, 9)
     g.add_edge(4, 1, 4)
     g.add_edge(32, 1, 4)
     g.add_edge(5, 1, 4)
     g.add_edge(5, 1, 3)
     g.add_edge(3, 1, 3)
     g.remove_node(3)
     g.add_edge(6, 1, 3)
     g.remove_edge(6, 1)
     self.assertIsNone(g.get_edge(6, 1))
     self.assertIsNone(g.get_edge(6, 6))
     self.assertIsNone(g.get_edge(4, 5))
     self.assertIsNone(g.get_edge(3, 9))
     self.assertEqual(g.get_edge(1, 2), 4)
     self.assertEqual(g.get_edge(2, 1), 7)