OutTreeTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use Fhaculty\Graph\Graph;
  3. use Graphp\Algorithms\Tree\OutTree;
  4. class OutTreeTest extends BaseDirectedTest
  5. {
  6. protected function createGraphTree()
  7. {
  8. // c1 <- root -> c2
  9. $graph = new Graph();
  10. $root = $graph->createVertex();
  11. $c1 = $graph->createVertex();
  12. $root->createEdgeTo($c1);
  13. $c2 = $graph->createVertex();
  14. $root->createEdgeTo($c2);
  15. return $graph;
  16. }
  17. protected function createTreeAlg(Graph $graph)
  18. {
  19. return new OutTree($graph);
  20. }
  21. protected function createGraphNonTree()
  22. {
  23. // v1 -> v3 <- v2 -> v4
  24. $graph = new Graph();
  25. $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v3'));
  26. $graph->createVertex('v2')->createEdgeTo($graph->getVertex('v3'));
  27. $graph->getVertex('v2')->createEdgeTo($graph->createVertex('v4'));
  28. return $graph;
  29. }
  30. protected function createGraphParallelEdge()
  31. {
  32. // v1 -> v2, v1 -> v2
  33. $graph = new Graph();
  34. $graph->createVertex('v1')->createEdgeTo($graph->createVertex('v2'));
  35. $graph->getVertex('v1')->createEdgeTo($graph->getVertex('v2'));
  36. return $graph;
  37. }
  38. }