22
33import static org .junit .jupiter .api .Assertions .assertEquals ;
44import static org .junit .jupiter .api .Assertions .assertThrows ;
5+
56import org .junit .jupiter .api .DisplayName ;
67import org .junit .jupiter .api .Test ;
78
@@ -10,58 +11,38 @@ class EdmondsKarpTest {
1011 @ Test
1112 @ DisplayName ("Classic CLRS network yields max flow 23" )
1213 void clrsExample () {
13- int [][] capacity = {
14- {0 , 16 , 13 , 0 , 0 , 0 },
15- {0 , 0 , 10 , 12 , 0 , 0 },
16- {0 , 4 , 0 , 0 , 14 , 0 },
17- {0 , 0 , 9 , 0 , 0 , 20 },
18- {0 , 0 , 0 , 7 , 0 , 4 },
19- {0 , 0 , 0 , 0 , 0 , 0 }
20- };
14+ int [][] capacity = {{0 , 16 , 13 , 0 , 0 , 0 }, {0 , 0 , 10 , 12 , 0 , 0 }, {0 , 4 , 0 , 0 , 14 , 0 }, {0 , 0 , 9 , 0 , 0 , 20 }, {0 , 0 , 0 , 7 , 0 , 4 }, {0 , 0 , 0 , 0 , 0 , 0 }};
2115 int maxFlow = EdmondsKarp .maxFlow (capacity , 0 , 5 );
2216 assertEquals (23 , maxFlow );
2317 }
2418
2519 @ Test
2620 @ DisplayName ("Disconnected network has zero flow" )
2721 void disconnectedGraph () {
28- int [][] capacity = {
29- {0 , 0 , 0 },
30- {0 , 0 , 0 },
31- {0 , 0 , 0 }
32- };
22+ int [][] capacity = {{0 , 0 , 0 }, {0 , 0 , 0 }, {0 , 0 , 0 }};
3323 int maxFlow = EdmondsKarp .maxFlow (capacity , 0 , 2 );
3424 assertEquals (0 , maxFlow );
3525 }
3626
3727 @ Test
3828 @ DisplayName ("Source equals sink returns zero" )
3929 void sourceEqualsSink () {
40- int [][] capacity = {
41- {0 , 5 },
42- {0 , 0 }
43- };
30+ int [][] capacity = {{0 , 5 }, {0 , 0 }};
4431 int maxFlow = EdmondsKarp .maxFlow (capacity , 0 , 0 );
4532 assertEquals (0 , maxFlow );
4633 }
4734
4835 @ Test
4936 @ DisplayName ("Invalid matrix throws exception" )
5037 void invalidMatrix () {
51- int [][] capacity = {
52- {0 , 1 },
53- {1 }
54- };
38+ int [][] capacity = {{0 , 1 }, {1 }};
5539 assertThrows (IllegalArgumentException .class , () -> EdmondsKarp .maxFlow (capacity , 0 , 1 ));
5640 }
5741
5842 @ Test
5943 @ DisplayName ("Negative capacity is rejected" )
6044 void negativeCapacity () {
61- int [][] capacity = {
62- {0 , -1 },
63- {0 , 0 }
64- };
45+ int [][] capacity = {{0 , -1 }, {0 , 0 }};
6546 assertThrows (IllegalArgumentException .class , () -> EdmondsKarp .maxFlow (capacity , 0 , 1 ));
6647 }
6748}
0 commit comments