FlowTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use Fhaculty\Graph\Graph;
  3. use Graphp\Algorithms\MaximumMatching\Flow;
  4. use Fhaculty\Graph\Loader\EdgeListBipartit;
  5. class FlowTest extends PHPUnit_Framework_TestCase
  6. {
  7. // /**
  8. // * run algorithm with small graph and check result against known result
  9. // */
  10. // public function testKnownResult()
  11. // {
  12. // $loader = new EdgeListBipartit(PATH_DATA . 'Matching_100_100.txt');
  13. // $loader->setEnableDirectedEdges(false);
  14. // $graph = $loader->createGraph();
  15. // $alg = new Flow($graph);
  16. // $this->assertEquals(100, $alg->getNumberOfMatches());
  17. // }
  18. public function testSingleEdge()
  19. {
  20. $graph = new Graph();
  21. $edge = $graph->createVertex(0)->setGroup(0)->createEdge($graph->createVertex(1)->setGroup(1));
  22. $alg = new Flow($graph);
  23. // correct number of edges
  24. $this->assertEquals(1, $alg->getNumberOfMatches());
  25. // actual edge instance returned
  26. $this->assertEquals(array($edge), $alg->getEdges()->getVector());
  27. // check
  28. $flowgraph = $alg->createGraph();
  29. $this->assertInstanceOf('Fhaculty\Graph\Graph', $flowgraph);
  30. }
  31. /**
  32. * expect exception for directed edges
  33. * @expectedException UnexpectedValueException
  34. */
  35. public function testInvalidDirected()
  36. {
  37. $graph = new Graph();
  38. $graph->createVertex(0)->setGroup(0)->createEdgeTo($graph->createVertex(1)->setGroup(1));
  39. $alg = new Flow($graph);
  40. $alg->getNumberOfMatches();
  41. }
  42. /**
  43. * expect exception for non-bipartit graphs
  44. * @expectedException UnexpectedValueException
  45. */
  46. public function testInvalidBipartit()
  47. {
  48. $graph = new Graph();
  49. $graph->createVertex(0)->setGroup(1)->createEdge($graph->createVertex(1)->setGroup(1));
  50. $alg = new Flow($graph);
  51. $alg->getNumberOfMatches();
  52. }
  53. }