Beispiel #1
0
 def test_remove_node(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     self.assertFalse(g.remove_node(14))
     self.assertTrue(g.remove_node(5))
     self.assertFalse(g.remove_node(5))
     self.assertTrue(g.remove_node(3))
     self.assertEqual(len(g.get_all_v()), 5)
Beispiel #2
0
 def test_get_all_v(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     dict = g.get_all_v()
     self.assertEqual(len(dict), 7)
     g.remove_node(6)
     dict = g.get_all_v()
     for i in range(6):
         self.assertEqual(dict[i].id, i)
Beispiel #3
0
 def test_v_size(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     g.add_node(0)
     g.add_node(2)
     g.remove_node(3)
     g.remove_node(3)
     g.remove_node(4)
     self.assertEqual(g.v_size(), 5)
Beispiel #4
0
 def test_get_node(self):
     g = DiGraph()
     for i in range(7):
         g.add_node(i)
     self.assertIsNone(g.get_node(8))
     g.remove_node(5)
     self.assertIsNone(g.get_node(5))
     list = [0, 1, 2, 3, 4, 6]
     sec_list = []
     for key in g.get_all_v().values():
         sec_list.append(g.get_node(key.id).id)
     self.assertListEqual(list, sec_list)
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)