Example #1
0
 public function testAddEdgeWhenNodesHaveBeenAddedBefore()
 {
     $undirectedGraph = new Graph(self::UNDIRECTED_GRAPH, self::NON_WEIGHTED_GRAPH);
     $numberOfNodes = 2;
     $nodeSet = array();
     for ($i = 0; $i < $numberOfNodes; $i++) {
         $nodeSet[] = self::NODE . $i;
     }
     $undirectedGraph->addNodeSet($nodeSet);
     $undirectedGraph->addEdge($nodeSet[0], $nodeSet[1]);
     $graph = $undirectedGraph->getAllNodes();
     $this->assertEquals($nodeSet[0], current($undirectedGraph->getEdges($nodeSet[1]))->getNode());
     $this->assertEquals($nodeSet[1], current($undirectedGraph->getEdges($nodeSet[0]))->getNode());
 }