Skip to content

Commit e79ec95

Browse files
committed
Add tests for WalkProperty::isCircuit() (100% coverage again)
1 parent 50753b1 commit e79ec95

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/Property/WalkPropertyTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,49 @@ public function testCycle()
8181
$this->assertTrue($alg->isHamiltonian());
8282
}
8383

84+
public function testCircuit()
85+
{
86+
// 1 -> 2 -> 1, 2 -> 2
87+
$graph = new Graph();
88+
$v1 = $graph->createVertex(1);
89+
$v2 = $graph->createVertex(2);
90+
$e1 = $v1->createEdgeTo($v2);
91+
$e2 = $v2->createEdgeTo($v1);
92+
$e3 = $v2->createEdgeTo($v2);
93+
94+
// 1 -> 2 -> 2 -> 1
95+
$walk = Walk::factoryFromEdges(array($e1, $e3, $e2), $v1);
96+
97+
$this->assertEquals(array(1, 2, 2, 1), $walk->getVerticesSequenceId());
98+
99+
$alg = new WalkProperty($walk);
100+
101+
$this->assertTrue($alg->isCycle());
102+
$this->assertTrue($alg->isCircuit());
103+
}
104+
105+
public function testNonCircuit()
106+
{
107+
// 1 -> 2 -> 1, 2 -> 2
108+
$graph = new Graph();
109+
$v1 = $graph->createVertex(1);
110+
$v2 = $graph->createVertex(2);
111+
$e1 = $v1->createEdgeTo($v2);
112+
$e2 = $v2->createEdgeTo($v1);
113+
$e3 = $v2->createEdgeTo($v2);
114+
115+
// non-circuit: taking loop twice
116+
// 1 -> 2 -> 2 -> 2 -> 1
117+
$walk = Walk::factoryFromEdges(array($e1, $e3, $e3, $e2), $v1);
118+
119+
$this->assertEquals(array(1, 2, 2, 2, 1), $walk->getVerticesSequenceId());
120+
121+
$alg = new WalkProperty($walk);
122+
123+
$this->assertTrue($alg->isCycle());
124+
$this->assertFalse($alg->isCircuit());
125+
}
126+
84127
public function testDigon()
85128
{
86129
// 1 -> 2 -> 1

0 commit comments

Comments
 (0)