Skip to content

Commit 777e0dc

Browse files
committed
Add tests with 100% code coverage for Algorithm\Flow
1 parent 16d8b96 commit 777e0dc

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tests/FlowTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ public function testGraphEmpty()
2020

2121
public function testEdgeWithZeroFlowIsConsideredFlow()
2222
{
23-
// 1 -- 2
23+
// 1 -> 2
2424
$graph = new Graph();
25-
$graph->createVertex(1)->createEdge($graph->createVertex(2))->setFlow(0);
25+
$graph->createVertex(1)->createEdgeTo($graph->createVertex(2))->setFlow(0);
2626

2727

2828
$alg = new AlgorithmFlow($graph);
2929

3030
$this->assertTrue($alg->hasFlow());
31+
$this->assertEquals(0, $alg->getFlowVertex($graph->getVertex(1)));
32+
$this->assertEquals(0, $alg->getFlowVertex($graph->getVertex(2)));
3133
}
3234

3335
/**
@@ -43,6 +45,8 @@ public function testGraphSimple(Graph $graph)
4345
$alg = new AlgorithmFlow($graph);
4446

4547
$this->assertFalse($alg->hasFlow());
48+
$this->assertEquals(0, $alg->getFlowVertex($graph->getVertex(1)));
49+
$this->assertEquals(0, $alg->getFlowVertex($graph->getVertex(2)));
4650

4751
return $graph;
4852
}
@@ -60,6 +64,8 @@ public function testGraphWithUnweightedEdges(Graph $graph)
6064
$alg = new AlgorithmFlow($graph);
6165

6266
$this->assertTrue($alg->hasFlow());
67+
$this->assertEquals(10, $alg->getFlowVertex($graph->getVertex(2)));
68+
$this->assertEquals(-10, $alg->getFlowVertex($graph->getVertex(3)));
6369
}
6470

6571
public function testGraphBalance()
@@ -74,4 +80,19 @@ public function testGraphBalance()
7480
$this->assertEquals(90, $alg->getBalance());
7581
$this->assertFalse($alg->isBalancedFlow());
7682
}
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+
}
7798
}

0 commit comments

Comments
 (0)