Skip to content

Commit 3403c9a

Browse files
committed
Add tests (100% coverage)
1 parent 89e999f commit 3403c9a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

tests/MinimumCostFlow/BaseMcfTest.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testIntermediaryVertices()
7676

7777
public function testEdgeCapacities()
7878
{
79-
// 1(+2) -[0/3/4]-> 2 -[0/4/5]-> 3 ->[0/6/-2]-> 3(-2)
79+
// 1(+2) -[0/3/4]-> 2 -[0/4/5]-> 3 ->[0/6/-2]-> 4(-2)
8080
$graph = new Graph();
8181
$v1 = $graph->createVertex(1)->setBalance(2);
8282
$v2 = $graph->createVertex(2);
@@ -90,6 +90,28 @@ public function testEdgeCapacities()
9090
$this->assertEquals(14, $alg->getWeightFlow()); // 2*4 + 2*5 + 2*-2
9191
}
9292

93+
public function testEdgeFlows()
94+
{
95+
// 1(+4) ---[3/4/2]---> 2 ---[3/3/3]---> 4(-4)
96+
// | | ^
97+
// | [0/2/1] |
98+
// | ↓ |
99+
// \-------[1/2/2]---> 3 ---[1/5/1]-------/
100+
$graph = new Graph();
101+
$v1 = $graph->createVertex(1)->setBalance(4);
102+
$v2 = $graph->createVertex(2);
103+
$v3 = $graph->createVertex(3);
104+
$v4 = $graph->createVertex(4)->setBalance(-4);
105+
$v1->createEdgeTo($v2)->setFlow(3)->setCapacity(4)->setWeight(2);
106+
$v2->createEdgeTo($v4)->setFlow(3)->setCapacity(3)->setWeight(3);
107+
$v1->createEdgeTo($v3)->setFlow(1)->setCapacity(2)->setWeight(2);
108+
$v3->createEdgeTo($v4)->setFlow(1)->setCapacity(5)->setWeight(1);
109+
$v2->createEdgeTo($v3)->setFlow(0)->setCapacity(2)->setWeight(1);
110+
111+
$alg = $this->createAlgorithm($graph);
112+
$this->assertEquals(14, $alg->getWeightFlow()); // 4*1 + 2*2 + 2*1 + 2*2
113+
}
114+
93115
/**
94116
* @expectedException UnexpectedValueException
95117
*/

0 commit comments

Comments
 (0)