Beispiel #1
0
 public function testGraphTree()
 {
     $graph = $this->createGraphTree();
     $root = $graph->getVertices()->getVertexFirst();
     $nonRoot = $graph->getVertices()->getMap();
     unset($nonRoot[$root->getId()]);
     $nonRoot = new Vertices($nonRoot);
     $c1 = $nonRoot->getVertexFirst();
     $tree = $this->createTreeAlg($graph);
     $this->assertTrue($tree->isTree());
     $this->assertSame($root, $tree->getVertexRoot());
     $this->assertSame($graph->getVertices()->getVector(), $tree->getVerticesSubtree($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesChildren($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesDescendant($root)->getVector());
     $this->assertSame($nonRoot->getVector(), $tree->getVerticesLeaf()->getVector());
     $this->assertSame(array(), $tree->getVerticesInternal()->getVector());
     $this->assertSame($root, $tree->getVertexParent($c1));
     $this->assertSame(array(), $tree->getVerticesChildren($c1)->getVector());
     $this->assertSame(array(), $tree->getVerticesDescendant($c1)->getVector());
     $this->assertSame(array($c1), $tree->getVerticesSubtree($c1)->getVector());
     $this->assertEquals(2, $tree->getDegree());
     $this->assertEquals(0, $tree->getDepthVertex($root));
     $this->assertEquals(1, $tree->getDepthVertex($c1));
     $this->assertEquals(1, $tree->getHeight());
     $this->assertEquals(1, $tree->getHeightVertex($root));
     $this->assertEquals(0, $tree->getHeightvertex($c1));
     return $tree;
 }
Beispiel #2
0
 /**
  *
  * @param Vertices $vertices
  * @depends testTwo
  */
 public function testTwoMatch(Vertices $vertices)
 {
     $verticesMatch = $vertices->getVerticesMatch(array($this, 'returnTrue'));
     $this->assertEquals($vertices->getVector(), $verticesMatch->getVector());
     $vertexMatch = $vertices->getVertexMatch(array($this, 'returnTrue'));
     $this->assertEquals($vertices->getVertexFirst(), $vertexMatch);
 }
Beispiel #3
0
 /**
  * get alternating sequence of vertex, edge, vertex, edge, ..., vertex
  *
  * @return array
  */
 public function getAlternatingSequence()
 {
     $edges = $this->edges->getVector();
     $vertices = $this->vertices->getVector();
     $ret = array();
     for ($i = 0, $l = count($this->edges); $i < $l; ++$i) {
         $ret[] = $vertices[$i];
         $ret[] = $edges[$i];
     }
     $ret[] = $vertices[$i];
     return $ret;
 }