DirectedTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use Graphp\Algorithms\Directed as AlgorithmDirected;
  3. use Fhaculty\Graph\Graph;
  4. class DirectedTest extends TestCase
  5. {
  6. public function testGraphEmpty()
  7. {
  8. $graph = new Graph();
  9. $alg = new AlgorithmDirected($graph);
  10. $this->assertFalse($alg->hasDirected());
  11. $this->assertFalse($alg->hasUndirected());
  12. $this->assertFalse($alg->isMixed());
  13. }
  14. public function testGraphUndirected()
  15. {
  16. // 1 -- 2
  17. $graph = new Graph();
  18. $graph->createVertex(1)->createEdge($graph->createVertex(2));
  19. $alg = new AlgorithmDirected($graph);
  20. $this->assertFalse($alg->hasDirected());
  21. $this->assertTrue($alg->hasUndirected());
  22. $this->assertFalse($alg->isMixed());
  23. }
  24. public function testGraphDirected()
  25. {
  26. // 1 -> 2
  27. $graph = new Graph();
  28. $graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
  29. $alg = new AlgorithmDirected($graph);
  30. $this->assertTrue($alg->hasDirected());
  31. $this->assertFalse($alg->hasUndirected());
  32. $this->assertFalse($alg->isMixed());
  33. }
  34. public function testGraphMixed()
  35. {
  36. // 1 -- 2 -> 3
  37. $graph = new Graph();
  38. $graph->createVertex(1)->createEdge($graph->createVertex(2));
  39. $graph->getVertex(2)->createEdgeTo($graph->createVertex(3));
  40. $alg = new AlgorithmDirected($graph);
  41. $this->assertTrue($alg->hasDirected());
  42. $this->assertTrue($alg->hasUndirected());
  43. $this->assertTrue($alg->isMixed());
  44. }
  45. }