Exemple #1
0
 public function testWalkWithinGraph()
 {
     // 1 -- 2 -- 3
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $v2 = $graph->createVertex(2);
     $v3 = $graph->createVertex(3);
     $e1 = $v1->createEdgeTo($v2);
     $e2 = $v2->createEdgeTo($v3);
     // construct partial walk "1 -- 2"
     $walk = Walk::factoryFromEdges(array($e1), $v1);
     $this->assertEquals(2, count($walk->getVertices()));
     $this->assertEquals(1, count($walk->getEdges()));
     $this->assertSame($v1, $walk->getVertices()->getVertexFirst());
     $this->assertSame($v2, $walk->getVertices()->getVertexLast());
     $this->assertSame(array($v1, $e1, $v2), $walk->getAlternatingSequence());
     $this->assertTrue($walk->isValid());
     $graphExpected = new Graph();
     $graphExpected->createVertex(1)->createEdgeTo($graphExpected->createVertex(2));
     $this->assertGraphEquals($graphExpected, $walk->createGraph());
     // construct same partial walk "1 -- 2"
     $walkVertices = Walk::factoryFromVertices(array($v1, $v2));
     $this->assertEquals(2, count($walkVertices->getVertices()));
     $this->assertEquals(1, count($walkVertices->getEdges()));
     $this->assertGraphEquals($graphExpected, $walkVertices->createGraph());
     return $walk;
 }
Exemple #2
0
 public function testFactoryFromVertices()
 {
     // 1 -- 2
     // \----/
     $graph = new Graph();
     $v1 = $graph->createVertex(1);
     $v2 = $graph->createVertex(2);
     $e1 = $v1->createEdge($v2)->setWeight(10);
     $e2 = $v1->createEdge($v2)->setWeight(20);
     // any edge in walk
     $walk = Walk::factoryFromVertices(array($v1, $v2));
     // edge with weight 10
     $walk = Walk::factoryFromVertices(array($v1, $v2), Edges::ORDER_WEIGHT);
     $this->assertSame($e1, $walk->getEdges()->getEdgeFirst());
     // edge with weight 20
     $walk = Walk::factoryFromVertices(array($v1, $v2), Edges::ORDER_WEIGHT, true);
     $this->assertSame($e2, $walk->getEdges()->getEdgeFirst());
 }