@@ -91,4 +91,126 @@ public void testComplexNetwork() {
91
91
int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 4 );
92
92
assertEquals (19 , maxFlow );
93
93
}
94
+
95
+ @ Test
96
+ public void testLargeNetwork () {
97
+ int vertexCount = 8 ;
98
+ int [][] capacity = new int [vertexCount ][vertexCount ];
99
+ int [][] flow = new int [vertexCount ][vertexCount ];
100
+
101
+ // Setting up a large network
102
+ capacity [0 ][1 ] = 10 ;
103
+ capacity [0 ][2 ] = 5 ;
104
+ capacity [1 ][3 ] = 15 ;
105
+ capacity [2 ][3 ] = 10 ;
106
+ capacity [1 ][4 ] = 10 ;
107
+ capacity [3 ][5 ] = 10 ;
108
+ capacity [4 ][5 ] = 5 ;
109
+ capacity [4 ][6 ] = 10 ;
110
+ capacity [5 ][7 ] = 10 ;
111
+ capacity [6 ][7 ] = 15 ;
112
+
113
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 7 );
114
+ assertEquals (15 , maxFlow ); // Maximum flow should be 15
115
+ }
116
+
117
+ @ Test
118
+ public void testMultipleSourcesAndSinks () {
119
+ int vertexCount = 7 ;
120
+ int [][] capacity = new int [vertexCount ][vertexCount ];
121
+ int [][] flow = new int [vertexCount ][vertexCount ];
122
+
123
+ // Creating multiple sources and sinks scenario
124
+ capacity [0 ][1 ] = 10 ; // Source 1
125
+ capacity [0 ][2 ] = 5 ;
126
+ capacity [1 ][3 ] = 15 ;
127
+ capacity [2 ][3 ] = 10 ;
128
+ capacity [3 ][4 ] = 10 ; // Sink 1
129
+ capacity [3 ][5 ] = 5 ;
130
+ capacity [3 ][6 ] = 10 ; // Sink 2
131
+ capacity [5 ][6 ] = 10 ;
132
+
133
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 4 );
134
+ assertEquals (10 , maxFlow ); // Maximum flow should be 10
135
+ }
136
+
137
+ @ Test
138
+ public void testDisconnectedGraph () {
139
+ int vertexCount = 6 ;
140
+ int [][] capacity = new int [vertexCount ][vertexCount ];
141
+ int [][] flow = new int [vertexCount ][vertexCount ];
142
+
143
+ // No connection between source and sink
144
+ capacity [0 ][1 ] = 10 ; // Only one edge not connected to the sink
145
+ capacity [1 ][2 ] = 10 ;
146
+ capacity [3 ][4 ] = 10 ;
147
+
148
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 5 );
149
+ assertEquals (0 , maxFlow ); // No flow should be possible
150
+ }
151
+
152
+ @ Test
153
+ public void testZeroCapacityEdge () {
154
+ int vertexCount = 4 ;
155
+ int [][] capacity = new int [vertexCount ][vertexCount ];
156
+ int [][] flow = new int [vertexCount ][vertexCount ];
157
+
158
+ // Including a zero capacity edge
159
+ capacity [0 ][1 ] = 10 ;
160
+ capacity [0 ][2 ] = 0 ; // Zero capacity
161
+ capacity [1 ][3 ] = 5 ;
162
+ capacity [2 ][3 ] = 10 ;
163
+
164
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 3 );
165
+ assertEquals (5 , maxFlow ); // Flow only possible through 0 -> 1 -> 3
166
+ }
167
+
168
+ @ Test
169
+ public void testAllEdgesZeroCapacity () {
170
+ int vertexCount = 5 ;
171
+ int [][] capacity = new int [vertexCount ][vertexCount ];
172
+ int [][] flow = new int [vertexCount ][vertexCount ];
173
+
174
+ // All edges with zero capacity
175
+ capacity [0 ][1 ] = 0 ;
176
+ capacity [1 ][2 ] = 0 ;
177
+ capacity [2 ][3 ] = 0 ;
178
+ capacity [3 ][4 ] = 0 ;
179
+
180
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 4 );
181
+ assertEquals (0 , maxFlow ); // No flow should be possible
182
+ }
183
+
184
+ @ Test
185
+ public void testCycleGraph () {
186
+ int vertexCount = 4 ;
187
+ int [][] capacity = new int [vertexCount ][vertexCount ];
188
+ int [][] flow = new int [vertexCount ][vertexCount ];
189
+
190
+ // Setting up a cycle
191
+ capacity [0 ][1 ] = 10 ;
192
+ capacity [1 ][2 ] = 5 ;
193
+ capacity [2 ][0 ] = 5 ; // This creates a cycle
194
+ capacity [1 ][3 ] = 15 ;
195
+ capacity [2 ][3 ] = 10 ;
196
+
197
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 3 );
198
+ assertEquals (10 , maxFlow ); // Maximum flow should be 10
199
+ }
200
+
201
+ @ Test
202
+ public void testFlowWithExcessCapacity () {
203
+ int vertexCount = 5 ;
204
+ int [][] capacity = new int [vertexCount ][vertexCount ];
205
+ int [][] flow = new int [vertexCount ][vertexCount ];
206
+
207
+ // Extra capacity in the flow
208
+ capacity [0 ][1 ] = 20 ;
209
+ capacity [1 ][2 ] = 10 ;
210
+ capacity [2 ][3 ] = 15 ;
211
+ capacity [1 ][3 ] = 5 ;
212
+
213
+ int maxFlow = FordFulkerson .networkFlow (vertexCount , capacity , flow , 0 , 3 );
214
+ assertEquals (15 , maxFlow ); // Maximum flow should be 15 (20 from 0->1 and 10->2, limited by 15->3)
215
+ }
94
216
}
0 commit comments