EulerianTest.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use Graphp\Algorithms\Eulerian as AlgorithmEulerian;
  3. use Fhaculty\Graph\Graph;
  4. class EulerianTest extends TestCase
  5. {
  6. public function testGraphEmpty()
  7. {
  8. $graph = new Graph();
  9. $alg = new AlgorithmEulerian($graph);
  10. $this->assertFalse($alg->hasCycle());
  11. }
  12. public function testGraphPairHasNoCycle()
  13. {
  14. // 1 -- 2
  15. $graph = new Graph();
  16. $v1 = $graph->createVertex(1);
  17. $v2 = $graph->createVertex(2);
  18. $v1->createEdge($v2);
  19. $alg = new AlgorithmEulerian($graph);
  20. $this->assertFalse($alg->hasCycle());
  21. }
  22. public function testGraphTriangleCycleIsNotBipartit()
  23. {
  24. // 1 -- 2 -- 3 -- 1
  25. $graph = new Graph();
  26. $v1 = $graph->createVertex(1);
  27. $v2 = $graph->createVertex(2);
  28. $v3 = $graph->createVertex(3);
  29. $v1->createEdge($v2);
  30. $v2->createEdge($v3);
  31. $v3->createEdge($v1);
  32. $alg = new AlgorithmEulerian($graph);
  33. $this->assertTrue($alg->hasCycle());
  34. }
  35. }