WeightTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. use Graphp\Algorithms\Weight as AlgorithmWeight;
  3. use Fhaculty\Graph\Graph;
  4. class WeightTest extends TestCase
  5. {
  6. public function testGraphEmpty()
  7. {
  8. $graph = new Graph();
  9. $alg = new AlgorithmWeight($graph);
  10. $this->assertEquals(null, $alg->getWeight());
  11. $this->assertEquals(0, $alg->getWeightFlow());
  12. $this->assertEquals(null, $alg->getWeightMin());
  13. $this->assertFalse($alg->isWeighted());
  14. return $graph;
  15. }
  16. /**
  17. *
  18. * @param Graph $graph
  19. * @depends testGraphEmpty
  20. */
  21. public function testGraphSimple(Graph $graph)
  22. {
  23. // 1 -> 2
  24. $graph->createVertex(1)->createEdgeTo($graph->createVertex(2))->setWeight(3)->setFlow(4);
  25. $alg = new AlgorithmWeight($graph);
  26. $this->assertEquals(3, $alg->getWeight());
  27. $this->assertEquals(12, $alg->getWeightFlow());
  28. $this->assertEquals(3, $alg->getWeightMin());
  29. $this->assertTrue($alg->isWeighted());
  30. return $graph;
  31. }
  32. /**
  33. *
  34. * @param Graph $graph
  35. * @depends testGraphSimple
  36. */
  37. public function testGraphWithUnweightedEdges(Graph $graph)
  38. {
  39. $graph->createVertex(5)->createEdgeTo($graph->createVertex(6))->setFlow(7);
  40. $alg = new AlgorithmWeight($graph);
  41. $this->assertEquals(3, $alg->getWeight());
  42. $this->assertEquals(12, $alg->getWeightFlow());
  43. $this->assertEquals(3, $alg->getWeightMin());
  44. $this->assertTrue($alg->isWeighted());
  45. }
  46. }