Skip to content

Commit 051c54f

Browse files
committed
Add tests with 100% coverage for Algorithm\Flow
1 parent da6d8f0 commit 051c54f

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/FlowTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
use Fhaculty\Graph\Algorithm\Flow as AlgorithmFlow;
4+
use Fhaculty\Graph\Graph;
5+
6+
class FlowaTest extends TestCase
7+
{
8+
public function testGraphEmpty()
9+
{
10+
$graph = new Graph();
11+
12+
$alg = new AlgorithmFlow($graph);
13+
14+
$this->assertFalse($alg->hasFlow());
15+
16+
return $graph;
17+
}
18+
19+
public function testEdgeWithZeroFlowIsConsideredFlow()
20+
{
21+
// 1 -- 2
22+
$graph = new Graph();
23+
$graph->createVertex(1)->createEdge($graph->createVertex(2))->setFlow(0);
24+
25+
26+
$alg = new AlgorithmFlow($graph);
27+
28+
$this->assertTrue($alg->hasFlow());
29+
}
30+
31+
/**
32+
*
33+
* @param Graph $graph
34+
* @depends testGraphEmpty
35+
*/
36+
public function testGraphSimple(Graph $graph)
37+
{
38+
// 1 -> 2
39+
$graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
40+
41+
$alg = new AlgorithmFlow($graph);
42+
43+
$this->assertFalse($alg->hasFlow());
44+
45+
return $graph;
46+
}
47+
48+
/**
49+
*
50+
* @param Graph $graph
51+
* @depends testGraphSimple
52+
*/
53+
public function testGraphWithUnweightedEdges(Graph $graph)
54+
{
55+
// additional flow edge: 2 -> 3
56+
$graph->getVertex(2)->createEdgeTo($graph->createVertex(3))->setFlow(10);
57+
58+
$alg = new AlgorithmFlow($graph);
59+
60+
$this->assertTrue($alg->hasFlow());
61+
}
62+
}

0 commit comments

Comments
 (0)