EdgeAttributesTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. use Fhaculty\Graph\Graph;
  3. use Fhaculty\Graph\Edge\Base as Edge;
  4. class EdgeAttributesTest extends TestCase
  5. {
  6. /**
  7. *
  8. * @var Edge
  9. */
  10. private $edge;
  11. public function setUp()
  12. {
  13. $graph = new Graph();
  14. $graph->createVertex(1);
  15. $graph->createVertex(2);
  16. // 1 -> 2
  17. $this->edge = $graph->getVertex(1)->createEdge($graph->getVertex(2));
  18. }
  19. public function testCanSetFlowAndCapacity()
  20. {
  21. $this->edge->setCapacity(100);
  22. $this->edge->setFlow(10);
  23. $this->assertEquals(90, $this->edge->getCapacityRemaining());
  24. }
  25. public function testCanSetFlowBeforeCapacity()
  26. {
  27. $this->edge->setFlow(20);
  28. $this->assertEquals(null, $this->edge->getCapacityRemaining());
  29. }
  30. /**
  31. * @expectedException RangeException
  32. */
  33. public function testFlowMustNotExceedCapacity()
  34. {
  35. $this->edge->setCapacity(20);
  36. $this->edge->setFlow(100);
  37. }
  38. /**
  39. * @expectedException RangeException
  40. */
  41. public function testCapacityMustBeGreaterThanFlow()
  42. {
  43. $this->edge->setFlow(100);
  44. $this->edge->setCapacity(20);
  45. }
  46. /**
  47. * @expectedException InvalidArgumentException
  48. */
  49. public function testWeightMustBeNumeric()
  50. {
  51. $this->edge->setWeight("10");
  52. }
  53. /**
  54. * @expectedException InvalidArgumentException
  55. */
  56. public function testCapacityMustBeNumeric()
  57. {
  58. $this->edge->setCapacity("10");
  59. }
  60. /**
  61. * @expectedException InvalidArgumentException
  62. */
  63. public function testCapacityMustBePositive()
  64. {
  65. $this->edge->setCapacity(-10);
  66. }
  67. /**
  68. * @expectedException InvalidArgumentException
  69. */
  70. public function testFlowMustBeNumeric()
  71. {
  72. $this->edge->setFlow("10");
  73. }
  74. /**
  75. * @expectedException InvalidArgumentException
  76. */
  77. public function testFlowMustBePositive()
  78. {
  79. $this->edge->setFlow(-10);
  80. }
  81. }