/** * @covers \Gliph\Traversal\DepthFirst::toposort * @expectedException Gliph\Exception\RuntimeException * Thrown by the visitor after adding a cycle to the graph. */ public function testToposort() { extract($this->v); $this->assertEquals(array($c, $d, $b, $a), DepthFirst::toposort($this->g, $a)); $this->g->addDirectedEdge($d, $a); DepthFirst::toposort($this->g, $a); }
/** * @covers \Gliph\Algorithm\ConnectedComponent::tarjan_scc() */ public function testTarjanScc() { $a = new TestVertex('a'); $b = new TestVertex('b'); $c = new TestVertex('c'); $d = new TestVertex('d'); $e = new TestVertex('e'); $f = new TestVertex('f'); $g = new TestVertex('g'); $h = new TestVertex('h'); $graph = new DirectedAdjacencyList(); $graph->addDirectedEdge($a, $d); $graph->addDirectedEdge($a, $b); $graph->addDirectedEdge($b, $c); $graph->addDirectedEdge($c, $d); $graph->addDirectedEdge($d, $a); $graph->addDirectedEdge($e, $d); $graph->addDirectedEdge($f, $g); $graph->addDirectedEdge($g, $h); $graph->addDirectedEdge($h, $f); $visitor = ConnectedComponent::tarjan_scc($graph); $expected_full = array(array($c, $b, $d, $a), array($e), array($h, $g, $f)); $this->assertEquals($expected_full, $visitor->getComponents()); $expected_full = array(array($c, $b, $d, $a), array($h, $g, $f)); $this->assertEquals($expected_full, $visitor->getConnectedComponents()); }
/** * @expectedException Gliph\Exception\RuntimeException * @covers Gliph\Visitor\DepthFirstBasicVisitor::onBackEdge * @covers Gliph\Visitor\DepthFirstBasicVisitor::onInitializeVertex */ public function testErrorOnCycle() { $this->g->addDirectedEdge($this->v['d'], $this->v['b']); DepthFirst::traverse($this->g, $this->vis); }