public function testComponents() { // 1 -- 2, 3 -> 4, 5 $graph = new Graph(); $v1 = $graph->createVertex(1); $v2 = $graph->createVertex(2); $v3 = $graph->createVertex(3); $v4 = $graph->createVertex(4); $v5 = $graph->createVertex(5); $e1 = $v1->createEdge($v2); $e2 = $v3->createEdgeTo($v4); $alg = new AlgorithmConnected($graph); $this->assertEquals(3, $alg->getNumberOfComponents()); $this->assertFalse($alg->isSingle()); $graphs = $alg->createGraphsComponents(); $this->assertCount(3, $graphs); $ge = new Graph(); $ge->createVertex(1)->createEdge($ge->createVertex(2)); $this->assertGraphEquals($ge, $alg->createGraphComponentVertex($v2)); $ge = new Graph(); $ge->createVertex(5); $this->assertEquals($ge, $alg->createGraphComponentVertex($v5)); }
private function disconnectGraph() { $components = new ConnectedComponents($this->graph); $this->disconnections = $components->createGraphsComponents(); }