VerticesTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use Fhaculty\Graph\Set\Vertices;
  3. use Fhaculty\Graph\Graph;
  4. use Fhaculty\Graph\Exception\InvalidArgumentException;
  5. class VerticesTest extends BaseVerticesTest
  6. {
  7. protected function createVertices(array $vertices)
  8. {
  9. return new Vertices($vertices);
  10. }
  11. public function testFactoryEmptyArray()
  12. {
  13. $vertices = Vertices::factory(array());
  14. $this->assertInstanceOf('Fhaculty\Graph\Set\Vertices', $vertices);
  15. $this->assertTrue($vertices->isEmpty());
  16. }
  17. /**
  18. * @expectedException InvalidArgumentException
  19. */
  20. public function testGetVertexOrderInvalidSortBy()
  21. {
  22. $graph = new Graph();
  23. $graph->createVertex(1);
  24. $vertices = $graph->getVertices();
  25. $vertices->getVertexOrder('not a valid callback');
  26. }
  27. /**
  28. * @expectedException InvalidArgumentException
  29. */
  30. public function testGetVicesOrderInvalidSortBy()
  31. {
  32. $vertices = $this->createVertices(array());
  33. $vertices->getVerticesOrder('not a valid callback');
  34. }
  35. public function testDuplicates()
  36. {
  37. $graph = new Graph();
  38. $v1 = $graph->createVertex(1);
  39. $vertices = $this->createVertices(array($v1, $v1, $v1));
  40. $this->assertInstanceOf('Fhaculty\Graph\Set\Vertices', $vertices);
  41. $this->assertCount(3, $vertices);
  42. $this->assertTrue($vertices->hasDuplicates());
  43. $verticesDistinct = $vertices->getVerticesDistinct();
  44. $this->assertInstanceOf('Fhaculty\Graph\Set\Vertices', $verticesDistinct);
  45. $this->assertCount(1, $verticesDistinct);
  46. $this->assertFalse($verticesDistinct->hasDuplicates());
  47. $this->assertSame($verticesDistinct, $verticesDistinct->getVerticesDistinct());
  48. }
  49. }