@@ -20,14 +20,16 @@ public function testGraphEmpty()
20
20
21
21
public function testEdgeWithZeroFlowIsConsideredFlow ()
22
22
{
23
- // 1 -- 2
23
+ // 1 -> 2
24
24
$ graph = new Graph ();
25
- $ graph ->createVertex (1 )->createEdge ($ graph ->createVertex (2 ))->setFlow (0 );
25
+ $ graph ->createVertex (1 )->createEdgeTo ($ graph ->createVertex (2 ))->setFlow (0 );
26
26
27
27
28
28
$ alg = new AlgorithmFlow ($ graph );
29
29
30
30
$ this ->assertTrue ($ alg ->hasFlow ());
31
+ $ this ->assertEquals (0 , $ alg ->getFlowVertex ($ graph ->getVertex (1 )));
32
+ $ this ->assertEquals (0 , $ alg ->getFlowVertex ($ graph ->getVertex (2 )));
31
33
}
32
34
33
35
/**
@@ -43,6 +45,8 @@ public function testGraphSimple(Graph $graph)
43
45
$ alg = new AlgorithmFlow ($ graph );
44
46
45
47
$ this ->assertFalse ($ alg ->hasFlow ());
48
+ $ this ->assertEquals (0 , $ alg ->getFlowVertex ($ graph ->getVertex (1 )));
49
+ $ this ->assertEquals (0 , $ alg ->getFlowVertex ($ graph ->getVertex (2 )));
46
50
47
51
return $ graph ;
48
52
}
@@ -60,6 +64,8 @@ public function testGraphWithUnweightedEdges(Graph $graph)
60
64
$ alg = new AlgorithmFlow ($ graph );
61
65
62
66
$ this ->assertTrue ($ alg ->hasFlow ());
67
+ $ this ->assertEquals (10 , $ alg ->getFlowVertex ($ graph ->getVertex (2 )));
68
+ $ this ->assertEquals (-10 , $ alg ->getFlowVertex ($ graph ->getVertex (3 )));
63
69
}
64
70
65
71
public function testGraphBalance ()
@@ -74,4 +80,19 @@ public function testGraphBalance()
74
80
$ this ->assertEquals (90 , $ alg ->getBalance ());
75
81
$ this ->assertFalse ($ alg ->isBalancedFlow ());
76
82
}
83
+
84
+ /**
85
+ * @expectedException UnexpectedValueException
86
+ */
87
+ public function testVertexWithUndirectedEdgeHasInvalidFlow ()
88
+ {
89
+ // 1 -- 2
90
+ $ graph = new Graph ();
91
+ $ graph ->createVertex (1 )->createEdge ($ graph ->createVertex (2 ))->setFlow (10 );
92
+
93
+
94
+ $ alg = new AlgorithmFlow ($ graph );
95
+
96
+ $ alg ->getFlowVertex ($ graph ->getVertex (1 ));
97
+ }
77
98
}
0 commit comments