Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
use Fhaculty\Graph\Graph;
use Graphp\Algorithms\Tree\Undirected;
class UndirectedTest extends TestCase
{
protected function createTree(Graph $graph)
{
return new Undirected($graph);
}
public function testNullGraph()
{
$graph = new Graph();
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
$this->assertTrue($tree->getVerticesInternal()->isEmpty());
$this->assertTrue($tree->getVerticesLeaf()->isEmpty());
}
public function testGraphTrivial()
{
$graph = new Graph();
$graph->createVertex('v1');
$tree = $this->createTree($graph);
$this->assertTrue($tree->isTree());
$this->assertSame(array(), $tree->getVerticesInternal()->getVector());
$this->assertSame(array(), $tree->getVerticesLeaf()->getVector());
}
public function testGraphSimplePair()
{
// v1 -- v2
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->createVertex('v2'));
$tree = $this->createTree($graph);
$this->assertTrue($tree->isTree());
$this->assertSame(array(), $tree->getVerticesInternal()->getVector());
$this->assertSame($graph->getVertices()->getVector(), $tree->getVerticesLeaf()->getVector());
}
public function testGraphSimpleLine()
{
// v1 -- v2 -- v3
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->createVertex('v2'));
$graph->getVertex('v2')->createEdge($graph->createVertex('v3'));
$tree = $this->createTree($graph);
$this->assertTrue($tree->isTree());
$this->assertSame(array($graph->getVertex('v2')), $tree->getVerticesInternal()->getVector());
$this->assertSame(array($graph->getVertex('v1'), $graph->getVertex('v3')), $tree->getVerticesLeaf()->getVector());
}
public function testGraphPairParallelIsNotTree()
{
// v1 -- v2 -- v1
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->createVertex('v2'));
$graph->getVertex('v1')->createEdge($graph->getVertex('v2'));
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
}
public function testGraphLoopIsNotTree()
{
// v1 -- v1
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->getVertex('v1'));
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
}
public function testGraphCycleIsNotTree()
{
// v1 -- v2 -- v3 -- v1
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->createVertex('v2'));
$graph->getVertex('v2')->createEdge($graph->createVertex('v3'));
$graph->getVertex('v3')->createEdge($graph->getVertex('v1'));
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
}
public function testGraphDirectedIsNotTree()
{
// v1 -> v2
$graph = new Graph();
$graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2'));
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
}
public function testGraphMixedIsNotTree()
{
// v1 -- v2 -> v3
$graph = new Graph();
$graph->createVertex('v1')->createEdge($graph->createVertex('v2'));
$graph->getVertex('v2')->createEdgeTo($graph->createVertex('v3'));
$tree = $this->createTree($graph);
$this->assertFalse($tree->isTree());
}
}