diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bd3732a..cc068d4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,20 @@ you spot any mistakes. accordingly. ([#72](https://github.com/clue/graph/issues/72)) +* BC break: Remove all occurances of `getNumberOfVertices()` and + `getNumberOfEdges()` ([#75](https://github.com/clue/graph/issues/75) and + [#48](https://github.com/clue/graph/issues/48)): + + | Old name | New name | + |---|---| + | `$set->getNumberOfVertices()` | `count($set->getVertices())` | + | `$set->getNumberOfEdges()` | `count($set->getEdges())` | + +* BC break: Replace base `Set` class with `Set\DualAggregate` interface. This + is unlikely to affect you, but might potentially break your custom + inheritance or polymorphism for algorithms. + ([#75](https://github.com/clue/graph/issues/75)) + * Feature: Add `Algorithm\ShortestPath\Base::hasVertex(Vertex $vertex)` to check whether a path to the given Vertex exists ([#62](https://github.com/clue/graph/issues/62)). diff --git a/lib/Fhaculty/Graph/Algorithm/BaseSet.php b/lib/Fhaculty/Graph/Algorithm/BaseDual.php similarity index 76% rename from lib/Fhaculty/Graph/Algorithm/BaseSet.php rename to lib/Fhaculty/Graph/Algorithm/BaseDual.php index c12cdec7..f657ff3d 100644 --- a/lib/Fhaculty/Graph/Algorithm/BaseSet.php +++ b/lib/Fhaculty/Graph/Algorithm/BaseDual.php @@ -3,7 +3,7 @@ namespace Fhaculty\Graph\Algorithm; use Fhaculty\Graph\Algorithm\Base; -use Fhaculty\Graph\Set; +use Fhaculty\Graph\Set\DualAggregate; use Fhaculty\Graph\Graph; use Fhaculty\Graph\Walk; @@ -12,12 +12,12 @@ * * @see Set */ -abstract class BaseSet extends Base +abstract class BaseDual extends Base { /** * Set to operate on * - * @var Set + * @var DualAggregate */ protected $set; @@ -26,7 +26,7 @@ abstract class BaseSet extends Base * * @param Graph|Walk|Set $graphOrWalk either the Graph or Walk to operate on (or the common base class Set) */ - public function __construct(Set $graphOrWalk) + public function __construct(DualAggregate $graphOrWalk) { $this->set = $graphOrWalk; } diff --git a/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php b/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php index cfaf0494..3da187b5 100644 --- a/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php +++ b/lib/Fhaculty/Graph/Algorithm/ConnectedComponents.php @@ -65,7 +65,6 @@ private function createSearch(Vertex $vertex) * connected here. * * @return boolean - * @uses AlgorithmSearchBreadthFirst::getNumberOfVertices() * @see self::getNumberOfComponents() */ public function isSingle() @@ -79,7 +78,7 @@ public function isSingle() } $alg = $this->createSearch($vertex); - return ($this->graph->getNumberOfVertices() === $alg->getNumberOfVertices()); + return (count($this->graph->getVertices()) === count($alg->getVertices())); } /** diff --git a/lib/Fhaculty/Graph/Algorithm/Directed.php b/lib/Fhaculty/Graph/Algorithm/Directed.php index b984c97d..e8ee9d24 100644 --- a/lib/Fhaculty/Graph/Algorithm/Directed.php +++ b/lib/Fhaculty/Graph/Algorithm/Directed.php @@ -11,7 +11,7 @@ * @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Direction * @link http://en.wikipedia.org/wiki/Digraph_%28mathematics%29 */ -class Directed extends BaseSet +class Directed extends BaseDual { /** * checks whether the graph has any directed edges (aka digraph) diff --git a/lib/Fhaculty/Graph/Algorithm/Flow.php b/lib/Fhaculty/Graph/Algorithm/Flow.php index 6ae06843..7130019b 100644 --- a/lib/Fhaculty/Graph/Algorithm/Flow.php +++ b/lib/Fhaculty/Graph/Algorithm/Flow.php @@ -18,7 +18,7 @@ * @link http://en.wikipedia.org/wiki/Flow_network * @see Algorithm\Balance */ -class Flow extends BaseSet +class Flow extends BaseDual { /** * check if this graph has any flow set (any edge has a non-NULL flow) diff --git a/lib/Fhaculty/Graph/Algorithm/Loop.php b/lib/Fhaculty/Graph/Algorithm/Loop.php index 4511edbb..d52bbdd4 100644 --- a/lib/Fhaculty/Graph/Algorithm/Loop.php +++ b/lib/Fhaculty/Graph/Algorithm/Loop.php @@ -2,7 +2,7 @@ namespace Fhaculty\Graph\Algorithm; -use Fhaculty\Graph\Algorithm\BaseSet; +use Fhaculty\Graph\Algorithm\BaseDual; use Fhaculty\Graph\Edge\Base as Edge; use Fhaculty\Graph\Vertex; @@ -14,7 +14,7 @@ * * @link http://en.wikipedia.org/wiki/Loop_%28graph_theory%29 */ -class Loop extends BaseSet +class Loop extends BaseDual { /** * checks whether this graph has any loops (edges from vertex to itself) diff --git a/lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php b/lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php index b9719d3e..66bc4d55 100644 --- a/lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php +++ b/lib/Fhaculty/Graph/Algorithm/MinimumCostFlow/SuccessiveShortestPath.php @@ -124,13 +124,12 @@ public function createGraph() * @param Graph $graph * @return boolean * @throws Exception if given graph is not a clone of the original graph (each vertex has to be present in both graphs) - * @uses Graph::getNumberOfVertices() * @uses Graph::getBalanace() * @uses Graph::getVertex() */ private function isBalanceReached(Graph $graph) { - if ($graph->getNumberOfVertices() !== $this->graph->getNumberOfVertices()) { + if (count($graph->getVertices()) !== count($this->graph->getVertices())) { throw new DomainException('Given graph does not appear to be a clone of input graph'); } foreach ($this->graph->getVertices()->getMap() as $vid => $vertex) { diff --git a/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php b/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php index 26095cc7..6c29a90e 100644 --- a/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php +++ b/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Kruskal.php @@ -125,7 +125,7 @@ public function getEdges() // definition of spanning tree: number of edges = number of vertices - 1 // above algorithm does not check isolated edges or may otherwise return multiple connected components => force check - if (count($returnEdges) !== ($this->graph->getNumberOfVertices() - 1)) { + if (count($returnEdges) !== (count($this->graph->getVertices()) - 1)) { throw new UnexpectedValueException('Graph is not connected'); } diff --git a/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Prim.php b/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Prim.php index adaa1fc5..51518462 100644 --- a/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Prim.php +++ b/lib/Fhaculty/Graph/Algorithm/MinimumSpanningTree/Prim.php @@ -35,7 +35,7 @@ public function getEdges() $returnEdges = array(); // iterate n-1 times (per definition, resulting MST MUST have n-1 edges) - for ($i = 0, $n = $this->startVertex->getGraph()->getNumberOfVertices() - 1; $i < $n; ++$i) { + for ($i = 0, $n = count($this->startVertex->getGraph()->getVertices()) - 1; $i < $n; ++$i) { $markInserted[$vertexCurrent->getId()] = true; // get unvisited vertex of the edge and add edges from new vertex diff --git a/lib/Fhaculty/Graph/Algorithm/Property/GraphProperty.php b/lib/Fhaculty/Graph/Algorithm/Property/GraphProperty.php index 88995529..90c21575 100644 --- a/lib/Fhaculty/Graph/Algorithm/Property/GraphProperty.php +++ b/lib/Fhaculty/Graph/Algorithm/Property/GraphProperty.php @@ -46,6 +46,6 @@ public function isNull() */ public function isTrivial() { - return ($this->graph->getEdges()->isEmpty() && $this->graph->getNumberOfVertices() === 1); + return ($this->graph->getEdges()->isEmpty() && count($this->graph->getVertices()) === 1); } } diff --git a/lib/Fhaculty/Graph/Algorithm/Property/WalkProperty.php b/lib/Fhaculty/Graph/Algorithm/Property/WalkProperty.php index fd31b44e..427ecf10 100644 --- a/lib/Fhaculty/Graph/Algorithm/Property/WalkProperty.php +++ b/lib/Fhaculty/Graph/Algorithm/Property/WalkProperty.php @@ -162,7 +162,7 @@ public function hasCycle() */ public function isLoop() { - return ($this->walk->getNumberOfEdges() === 1 && $this->isCycle()); + return (count($this->walk->getEdges()) === 1 && $this->isCycle()); } /** @@ -214,7 +214,7 @@ public function hasLoop() public function isDigon() { // exactly 2 edges - return ($this->walk->getNumberOfEdges() === 2 && + return (count($this->walk->getEdges()) === 2 && // no duplicate edges !$this->hasArrayDuplicates($this->walk->getEdges()->getVector()) && // exactly two distinct vertices @@ -238,7 +238,7 @@ public function isDigon() public function isTriangle() { // exactly 3 (implicitly distinct) edges - return ($this->walk->getNumberOfEdges() === 3 && + return (count($this->walk->getEdges()) === 3 && // exactly three distinct vertices count($this->walk->getVertices()->getVerticesDistinct()) === 3 && // this is actually a cycle diff --git a/lib/Fhaculty/Graph/Algorithm/Search/Base.php b/lib/Fhaculty/Graph/Algorithm/Search/Base.php index a7c37856..a47bf921 100644 --- a/lib/Fhaculty/Graph/Algorithm/Search/Base.php +++ b/lib/Fhaculty/Graph/Algorithm/Search/Base.php @@ -47,17 +47,6 @@ protected function getVerticesAdjacent(Vertex $vertex) } } - /** - * get total number of vertices the start vertex is connected to - * - * @return int - * @uses AlgorithmSearch::getVertices() - */ - public function getNumberOfVertices() - { - return count($this->getVertices()); - } - /** * get set of all Vertices that can be reached from start vertex * diff --git a/lib/Fhaculty/Graph/Algorithm/ShortestPath/Dijkstra.php b/lib/Fhaculty/Graph/Algorithm/ShortestPath/Dijkstra.php index 35759d23..3600d7b3 100644 --- a/lib/Fhaculty/Graph/Algorithm/ShortestPath/Dijkstra.php +++ b/lib/Fhaculty/Graph/Algorithm/ShortestPath/Dijkstra.php @@ -46,7 +46,7 @@ public function getEdges() $isFirst = true; // Repeat until all vertices have been marked - $totalCountOfVertices = $this->vertex->getGraph()->getNumberOfVertices(); + $totalCountOfVertices = count($this->vertex->getGraph()->getVertices()); for ($i = 0; $i < $totalCountOfVertices; ++$i) { $currentVertex = NULL; $currentVertexId = NULL; diff --git a/lib/Fhaculty/Graph/Algorithm/ShortestPath/MooreBellmanFord.php b/lib/Fhaculty/Graph/Algorithm/ShortestPath/MooreBellmanFord.php index bd9b2051..e954230a 100644 --- a/lib/Fhaculty/Graph/Algorithm/ShortestPath/MooreBellmanFord.php +++ b/lib/Fhaculty/Graph/Algorithm/ShortestPath/MooreBellmanFord.php @@ -79,7 +79,7 @@ public function getEdges() // the usal algorithm says we repeat (n-1) times. // but because we also want to check for loop edges on the start vertex, // we have to add an additional step: - $numSteps = $this->vertex->getGraph()->getNumberOfVertices(); + $numSteps = count($this->vertex->getGraph()->getVertices()); $edges = $this->vertex->getGraph()->getEdges(); $changed = true; diff --git a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php index e97acfee..00b02f55 100644 --- a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php +++ b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/Bruteforce.php @@ -108,7 +108,7 @@ protected function getGraph() */ public function getEdges() { - $this->numEdges = $this->graph->getNumberOfVertices(); + $this->numEdges = count($this->graph->getVertices()); if ($this->numEdges < 3) { throw new UnderflowException('Needs at least 3 vertices'); } diff --git a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/NearestNeighbor.php b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/NearestNeighbor.php index fc55f5b2..e198045a 100644 --- a/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/NearestNeighbor.php +++ b/lib/Fhaculty/Graph/Algorithm/TravelingSalesmanProblem/NearestNeighbor.php @@ -40,7 +40,7 @@ public function getEdges() { $returnEdges = array(); - $n = $this->vertex->getGraph()->getNumberOfVertices(); + $n = count($this->vertex->getGraph()->getVertices()); $vertex = $this->vertex; $visitedVertices = array($vertex->getId() => true); diff --git a/lib/Fhaculty/Graph/Algorithm/Tree/BaseDirected.php b/lib/Fhaculty/Graph/Algorithm/Tree/BaseDirected.php index e67e99c8..ef557793 100644 --- a/lib/Fhaculty/Graph/Algorithm/Tree/BaseDirected.php +++ b/lib/Fhaculty/Graph/Algorithm/Tree/BaseDirected.php @@ -96,7 +96,7 @@ public function isTree() } // check number of vertices reachable from root should match total number of vertices - return ($num === $this->graph->getNumberOfVertices()); + return ($num === count($this->graph->getVertices())); } /** diff --git a/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php b/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php index 8f55d4af..01157d9b 100644 --- a/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php +++ b/lib/Fhaculty/Graph/Algorithm/Tree/Undirected.php @@ -70,7 +70,7 @@ public function isTree() return false; } - return (count($vertices) === $this->graph->getNumberOfVertices()); + return (count($vertices) === count($this->graph->getVertices())); } /** diff --git a/lib/Fhaculty/Graph/Algorithm/Weight.php b/lib/Fhaculty/Graph/Algorithm/Weight.php index e8e548bd..38445635 100644 --- a/lib/Fhaculty/Graph/Algorithm/Weight.php +++ b/lib/Fhaculty/Graph/Algorithm/Weight.php @@ -15,7 +15,7 @@ * * @link http://en.wikipedia.org/wiki/Glossary_of_graph_theory#Weighted_graphs_and_networks */ -class Weight extends BaseSet +class Weight extends BaseDual { /** * checks whether this graph has any weighted edges diff --git a/lib/Fhaculty/Graph/Graph.php b/lib/Fhaculty/Graph/Graph.php index b18cd6d1..12392d65 100644 --- a/lib/Fhaculty/Graph/Graph.php +++ b/lib/Fhaculty/Graph/Graph.php @@ -20,8 +20,9 @@ use Fhaculty\Graph\Set\Vertices; use Fhaculty\Graph\Set\VerticesMap; use Fhaculty\Graph\Set\Edges; +use Fhaculty\Graph\Set\DualAggregate; -class Graph extends Set +class Graph implements DualAggregate { /** * @var ExporterInterface|null diff --git a/lib/Fhaculty/Graph/Set.php b/lib/Fhaculty/Graph/Set.php deleted file mode 100644 index 3f621efb..00000000 --- a/lib/Fhaculty/Graph/Set.php +++ /dev/null @@ -1,52 +0,0 @@ -getVertices()); - } - - /** - * return number of edges - * - * @return int - */ - public function getNumberOfEdges() - { - return count($this->getEdges()); - } -} diff --git a/lib/Fhaculty/Graph/Set/DualAggregate.php b/lib/Fhaculty/Graph/Set/DualAggregate.php new file mode 100644 index 00000000..6bd370c3 --- /dev/null +++ b/lib/Fhaculty/Graph/Set/DualAggregate.php @@ -0,0 +1,30 @@ +assertEquals(1, $walk->getNumberOfVertices()); - $this->assertEquals(0, $walk->getNumberOfEdges()); + $this->assertEquals(1, count($walk->getVertices())); + $this->assertEquals(0, count($walk->getEdges())); $alg = new WalkProperty($walk); @@ -67,8 +67,8 @@ public function testCycle() $walk = Walk::factoryFromEdges(array($e1, $e2), $v1); - $this->assertEquals(3, $walk->getNumberOfVertices()); - $this->assertEquals(2, $walk->getNumberOfEdges()); + $this->assertEquals(3, count($walk->getVertices())); + $this->assertEquals(2, count($walk->getEdges())); $alg = new WalkProperty($walk); @@ -170,8 +170,8 @@ public function testSimplePathWithinGraph() // only use "2 -- 2" part $walk = Walk::factoryFromEdges(array($e2), $v2); - $this->assertEquals(2, $walk->getNumberOfVertices()); - $this->assertEquals(1, $walk->getNumberOfEdges()); + $this->assertEquals(2, count($walk->getVertices())); + $this->assertEquals(1, count($walk->getEdges())); $alg = new WalkProperty($walk); diff --git a/tests/Fhaculty/Graph/Algorithm/ShortestPath/BaseShortestPathTest.php b/tests/Fhaculty/Graph/Algorithm/ShortestPath/BaseShortestPathTest.php index 9f85222b..65fa5ee4 100644 --- a/tests/Fhaculty/Graph/Algorithm/ShortestPath/BaseShortestPathTest.php +++ b/tests/Fhaculty/Graph/Algorithm/ShortestPath/BaseShortestPathTest.php @@ -79,7 +79,7 @@ public function testGraphCycle() $this->assertEquals($expectedWeight, $alg->getDistance($v1)); $walk = $alg->getWalkTo($v1); - $this->assertEquals(2, $walk->getNumberOfEdges()); + $this->assertEquals(2, count($walk->getEdges())); } /** diff --git a/tests/Fhaculty/Graph/GraphTest.php b/tests/Fhaculty/Graph/GraphTest.php index d59c7521..ad09d99e 100644 --- a/tests/Fhaculty/Graph/GraphTest.php +++ b/tests/Fhaculty/Graph/GraphTest.php @@ -185,7 +185,7 @@ public function testCreateMultigraph() $e1 = $v1->createEdge($v2); $e2 = $v1->createEdge($v2); - $this->assertEquals(2, $graph->getNumberOfEdges()); + $this->assertEquals(2, count($graph->getEdges())); $this->assertEquals(2, count($v1->getEdges())); $this->assertEquals(array(2, 2), $v1->getVerticesEdge()->getIds()); @@ -202,7 +202,7 @@ public function testCreateMixedGraph() $v1->createEdge($v2); $v2->createEdgeTo($v3); - $this->assertEquals(2, $graph->getNumberOfEdges()); + $this->assertEquals(2, count($graph->getEdges())); $this->assertEquals(2, count($v2->getEdges())); $this->assertEquals(2, count($v2->getEdgesOut())); @@ -219,7 +219,7 @@ public function testCreateVerticesNone() $this->assertEquals(array(), $graph->createVertices(0)->getVector()); $this->assertEquals(array(), $graph->createVertices(array())->getVector()); - $this->assertEquals(0, $graph->getNumberOfVertices()); + $this->assertEquals(0, count($graph->getVertices())); } /** @@ -274,7 +274,7 @@ public function testCreateVerticesAtomic() $this->fail('Should be unable to create vertices because of duplicate IDs'); } catch (OverflowException $ignoreExpected) { - $this->assertEquals(10, $graph->getNumberOfVertices()); + $this->assertEquals(10, count($graph->getVertices())); } try { @@ -282,7 +282,7 @@ public function testCreateVerticesAtomic() $this->fail('Should be unable to create vertices because of duplicate IDs'); } catch (InvalidArgumentException $ignoreExpected) { - $this->assertEquals(10, $graph->getNumberOfVertices()); + $this->assertEquals(10, count($graph->getVertices())); } } @@ -411,7 +411,7 @@ public function testCreateGraphCloneVertices() $graphClone = $graph->createGraphCloneVertices(array(1 => $v1, 2 => $v2)); - $this->assertEquals(2, $graphClone->getNumberOfVertices()); - $this->assertEquals(1, $graphClone->getNumberOfEdges()); + $this->assertEquals(2, count($graphClone->getVertices())); + $this->assertEquals(1, count($graphClone->getEdges())); } } diff --git a/tests/Fhaculty/Graph/Loader/CompleteGraphTest.php b/tests/Fhaculty/Graph/Loader/CompleteGraphTest.php index b3df703b..b39a7f39 100644 --- a/tests/Fhaculty/Graph/Loader/CompleteGraphTest.php +++ b/tests/Fhaculty/Graph/Loader/CompleteGraphTest.php @@ -28,8 +28,8 @@ public function testUndirected() $loader = new CompleteGraph($n); $graph = $loader->createGraph(); - $this->assertEquals($n, $graph->getNumberOfVertices()); - $this->assertEquals($n*($n-1)/2, $graph->getNumberOfEdges()); + $this->assertEquals($n, count($graph->getVertices())); + $this->assertEquals($n*($n-1)/2, count($graph->getEdges())); } public function testDirected() @@ -40,8 +40,8 @@ public function testDirected() $loader->setEnableDirectedEdges(true); $graph = $loader->createGraph(); - $this->assertEquals($n, $graph->getNumberOfVertices()); - $this->assertEquals($n*($n-1), $graph->getNumberOfEdges()); // n*(n-1) for directed graphs + $this->assertEquals($n, count($graph->getVertices())); + $this->assertEquals($n*($n-1), count($graph->getEdges())); // n*(n-1) for directed graphs $alg = new Directed($graph); $this->assertTrue($alg->isDirected()); diff --git a/tests/Fhaculty/Graph/WalkTest.php b/tests/Fhaculty/Graph/WalkTest.php index b8f90745..e0f0239f 100644 --- a/tests/Fhaculty/Graph/WalkTest.php +++ b/tests/Fhaculty/Graph/WalkTest.php @@ -26,8 +26,8 @@ public function testWalkPath() $walk = Walk::factoryFromEdges(array($e1, $e2), $v1); - $this->assertEquals(3, $walk->getNumberOfVertices()); - $this->assertEquals(2, $walk->getNumberOfEdges()); + $this->assertEquals(3, count($walk->getVertices())); + $this->assertEquals(2, count($walk->getEdges())); $this->assertSame($v1, $walk->getVertexSource()); $this->assertSame($v3, $walk->getVertexTarget()); $this->assertSame(array($v1, $e1, $v2, $e2, $v3), $walk->getAlternatingSequence()); @@ -64,8 +64,8 @@ public function testWalkWithinGraph() // construct partial walk "1 -- 2" $walk = Walk::factoryFromEdges(array($e1), $v1); - $this->assertEquals(2, $walk->getNumberOfVertices()); - $this->assertEquals(1, $walk->getNumberOfEdges()); + $this->assertEquals(2, count($walk->getVertices())); + $this->assertEquals(1, count($walk->getEdges())); $this->assertSame($v1, $walk->getVertexSource()); $this->assertSame($v2, $walk->getVertexTarget()); $this->assertSame(array($v1, $e1, $v2), $walk->getAlternatingSequence()); @@ -79,8 +79,8 @@ public function testWalkWithinGraph() // construct same partial walk "1 -- 2" $walkVertices = Walk::factoryFromVertices(array($v1, $v2)); - $this->assertEquals(2, $walkVertices->getNumberOfVertices()); - $this->assertEquals(1, $walkVertices->getNumberOfEdges()); + $this->assertEquals(2, count($walkVertices->getVertices())); + $this->assertEquals(1, count($walkVertices->getEdges())); $this->assertGraphEquals($graphExpected, $walkVertices->createGraph()); @@ -96,8 +96,8 @@ public function testWalkLoop() $walk = Walk::factoryFromEdges(array($e1), $v1); - $this->assertEquals(2, $walk->getNumberOfVertices()); - $this->assertEquals(1, $walk->getNumberOfEdges()); + $this->assertEquals(2, count($walk->getVertices())); + $this->assertEquals(1, count($walk->getEdges())); $this->assertSame($v1, $walk->getVertexSource()); $this->assertSame($v1, $walk->getVertexTarget()); $this->assertTrue($walk->isValid()); @@ -129,8 +129,8 @@ public function testWalkLoopCycle() $walk = Walk::factoryCycleFromEdges(array($e1), $v1); - $this->assertEquals(2, $walk->getNumberOfVertices()); - $this->assertEquals(1, $walk->getNumberOfEdges()); + $this->assertEquals(2, count($walk->getVertices())); + $this->assertEquals(1, count($walk->getEdges())); $this->assertSame($v1, $walk->getVertexSource()); $this->assertSame($v1, $walk->getVertexTarget()); $this->assertTrue($walk->isValid()); @@ -148,8 +148,8 @@ public function testWalkCycleFromVerticesAutocomplete() // should actually be v1, v2, v1, but cycle factory automatically adds missing vertex + edge $walk = Walk::factoryCycleFromVertices(array($v1, $v2)); - $this->assertEquals(3, $walk->getNumberOfVertices()); - $this->assertEquals(2, $walk->getNumberOfEdges()); + $this->assertEquals(3, count($walk->getVertices())); + $this->assertEquals(2, count($walk->getEdges())); $this->assertSame($v1, $walk->getVertexSource()); $this->assertSame($v1, $walk->getVertexTarget()); $this->assertTrue($walk->isValid()); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 15569fcb..723a8280 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,8 +14,8 @@ protected function assertGraphEquals(Graph $expected, Graph $actual) { $f = function(Graph $graph){ $ret = get_class($graph); - $ret .= PHP_EOL . 'vertices: ' . $graph->getNumberOfVertices(); - $ret .= PHP_EOL . 'edges: ' . $graph->getNumberOfEdges(); + $ret .= PHP_EOL . 'vertices: ' . count($graph->getVertices()); + $ret .= PHP_EOL . 'edges: ' . count($graph->getEdges()); return $ret; };