CompleteTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use Graphp\Algorithms\Complete as AlgorithmComplete;
  3. use Fhaculty\Graph\Graph;
  4. class CompleteTest extends TestCase
  5. {
  6. public function testGraphEmptyK0()
  7. {
  8. $graph = new Graph();
  9. $alg = new AlgorithmComplete($graph);
  10. $this->assertTrue($alg->isComplete());
  11. }
  12. public function testGraphSingleTrivialK1()
  13. {
  14. $graph = new Graph();
  15. $graph->createVertex(1);
  16. $alg = new AlgorithmComplete($graph);
  17. $this->assertTrue($alg->isComplete());
  18. }
  19. public function testGraphSimplePairK2()
  20. {
  21. // 1 -- 2
  22. $graph = new Graph();
  23. $graph->createVertex(1)->createEdge($graph->createVertex(2));
  24. $alg = new AlgorithmComplete($graph);
  25. $this->assertTrue($alg->isComplete());
  26. }
  27. public function testGraphSingleDirectedIsNotComplete()
  28. {
  29. // 1 -> 2
  30. $graph = new Graph();
  31. $graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
  32. $alg = new AlgorithmComplete($graph);
  33. $this->assertFalse($alg->isComplete());
  34. }
  35. public function testAdditionalEdgesToNotAffectCompleteness()
  36. {
  37. // 1 -> 2
  38. // 1 -- 2
  39. // 2 -> 1
  40. // 1 -> 1
  41. $graph = new Graph();
  42. $graph->createVertex(1)->createEdgeTo($graph->createVertex(2));
  43. $graph->getVertex(1)->createEdge($graph->getVertex(2));
  44. $graph->getVertex(2)->createEdgeTo($graph->getVertex(1));
  45. $graph->getVertex(1)->createEdgeTo($graph->getVertex(1));
  46. $alg = new AlgorithmComplete($graph);
  47. $this->assertTrue($alg->isComplete());
  48. }
  49. }