Skip to content

Commit b795dda

Browse files
committed
Add separate test case for unweighted edges
1 parent f0297b5 commit b795dda

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/ShortestPath/BaseShortestPathTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,24 @@ public function testSeparateGraphsAreNotReachable()
116116
$alg->getEdgesTo($vg2);
117117
}
118118

119+
public function testGraphUnweighted()
120+
{
121+
// 1 -> 2
122+
$graph = new Graph();
123+
$v1 = $graph->createVertex(1);
124+
$v2 = $graph->createVertex(2);
125+
$e1 = $v1->createEdgeTo($v2);
126+
127+
$alg = $this->createAlg($v1);
128+
129+
$expectedWeight = $this->getExpectedWeight(array($e1));
130+
$this->assertEquals($expectedWeight, $alg->getDistance($v2));
131+
$this->assertEquals(array(2 => $expectedWeight), $alg->getDistanceMap());
132+
$this->assertEquals(array($e1), $alg->getEdges()->getVector());
133+
$this->assertEquals(array($e1), $alg->getEdgesTo($v2)->getVector());
134+
$this->assertEquals(array(2), $alg->getVertices()->getIds());
135+
}
136+
119137
public function testGraphTwoComponents()
120138
{
121139
// 1 -[10]-> 2

tests/ShortestPath/MooreBellmanFordTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ public function testLoopNegativeWeightIsCycle()
7272

7373
public function testNegativeComponentHasCycle()
7474
{
75-
// 1 -- 2 3 --[-1]--> 4
76-
// ^ |
77-
// \---[-2]----/
75+
// 1 -[1]-> 2 3 --[-1]--> 4
76+
// ^ |
77+
// \---[-2]----/
7878
$graph = new Graph();
7979
$v1 = $graph->createVertex(1);
8080
$v2 = $graph->createVertex(2);
8181
$v3 = $graph->createVertex(3);
8282
$v4 = $graph->createVertex(4);
83-
$e1 = $v1->createEdge($v2);
83+
$e1 = $v1->createEdgeTo($v2)->setWeight(1);
8484
$e2 = $v3->createEdgeTo($v4)->setWeight(-1);
8585
$e3 = $v4->createEdgeTo($v3)->setWeight(-2);
8686

0 commit comments

Comments
 (0)