11from algorithms .graph import Tarjan
22from algorithms .graph import check_bipartite
33from algorithms .graph .dijkstra import Dijkstra
4+ from algorithms .graph import maximum_flow_bfs
5+ from algorithms .graph import maximum_flow_dfs
46from algorithms .graph import all_pairs_shortest_path
57from algorithms .graph import bellman_ford
68
9+
710import unittest
811
912
@@ -78,6 +81,49 @@ def test_dijkstra(self):
7881
7982 self .assertEqual (g .dijkstra (0 ), [0 , 4 , 12 , 19 , 21 , 11 , 9 , 8 , 14 ])
8083
84+ class TestMaximum_Flow_Bfs (unittest .TestCase ):
85+
86+ """
87+ Test for the file def maximum_flow_bfs.py
88+ Arguments:
89+ unittest {[type]} -- [description]
90+ """
91+
92+ def test_maximum_flow_bfs (self ):
93+ graph = [
94+ [0 , 16 , 13 , 0 , 0 , 0 ],
95+ [0 , 0 , 10 , 12 , 0 , 0 ],
96+ [0 , 4 , 0 , 0 , 14 , 0 ],
97+ [0 , 0 , 9 , 0 , 0 , 20 ],
98+ [0 , 0 , 0 , 7 , 0 , 4 ],
99+ [0 , 0 , 0 , 0 , 0 , 0 ]
100+ ]
101+ maximum_flow = maximum_flow_bfs (graph )
102+
103+ self .assertEqual (maximum_flow , 23 )
104+
105+ class TestMaximum_Flow_Dfs (unittest .TestCase ):
106+
107+ """
108+ Test for the file def maximum_flow_dfs.py
109+ Arguments:
110+ unittest {[type]} -- [description]
111+ """
112+
113+ def test_maximum_flow_dfs (self ):
114+ graph = [
115+ [0 , 16 , 13 , 0 , 0 , 0 ],
116+ [0 , 0 , 10 , 12 , 0 , 0 ],
117+ [0 , 4 , 0 , 0 , 14 , 0 ],
118+ [0 , 0 , 9 , 0 , 0 , 20 ],
119+ [0 , 0 , 0 , 7 , 0 , 4 ],
120+ [0 , 0 , 0 , 0 , 0 , 0 ]
121+ ]
122+ maximum_flow = maximum_flow_dfs (graph )
123+
124+ self .assertEqual (maximum_flow , 23 )
125+
126+
81127class TestAll_Pairs_Shortest_Path (unittest .TestCase ):
82128
83129 def test_all_pairs_shortest_path (self ):
@@ -88,7 +134,14 @@ def test_all_pairs_shortest_path(self):
88134 [0.867 , 0.119 , 0.352 , 0.398 , 0 ]]
89135 result = all_pairs_shortest_path (graph )
90136
91- self .assertEqual (result , [[0 , 0.1 , 0.101 , 0.142 , 0.277 ], [0.436 , 0 , 0.191 , 0.192 , 0.34299999999999997 ], [0.245 , 0.345 , 0 , 0.333 , 0.484 ], [0.706 , 0.27 , 0.46099999999999997 , 0 , 0.151 ], [0.5549999999999999 , 0.119 , 0.31 , 0.311 , 0 ]])
137+ self .assertEqual (result , [
138+ [0 , 0.1 , 0.101 , 0.142 , 0.277 ],
139+ [0.436 , 0 , 0.191 , 0.192 , 0.34299999999999997 ],
140+ [0.245 , 0.345 , 0 , 0.333 , 0.484 ],
141+ [0.706 , 0.27 , 0.46099999999999997 , 0 , 0.151 ],
142+ [0.5549999999999999 , 0.119 , 0.31 , 0.311 , 0 ],
143+ ])
144+
92145
93146class TestBellmanFord (unittest .TestCase ):
94147 def test_bellman_ford (self ):
@@ -111,3 +164,4 @@ def test_bellman_ford(self):
111164 }
112165
113166 self .assertEqual (True , bellman_ford (graph2 , 'a' ))
167+
0 commit comments