File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -354,7 +354,7 @@ public function getVerticesEdgeFrom()
354354 */
355355 public function destroy ()
356356 {
357- foreach ($ this ->edges as $ edge ) {
357+ foreach ($ this ->getEdges ()-> getEdgesDistinct () as $ edge ) {
358358 $ edge ->destroy ();
359359 }
360360 $ this ->graph ->removeVertex ($ this );
Original file line number Diff line number Diff line change @@ -99,6 +99,18 @@ public function testLoop()
9999 $ this ->assertSame ($ this ->v1 , $ edge ->getVertexToFrom ($ this ->v1 ));
100100 }
101101
102+ public function testRemoveWithLoop ()
103+ {
104+ $ edge = $ this ->createEdgeLoop ();
105+
106+ $ this ->assertEquals (array ($ this ->edge , $ edge ), $ this ->graph ->getEdges ()->getVector ());
107+
108+ $ edge ->destroy ();
109+
110+ $ this ->assertEquals (array ($ this ->edge ), $ this ->graph ->getEdges ()->getVector ());
111+ $ this ->assertEquals (array ($ this ->v1 , $ this ->v2 ), $ this ->graph ->getVertices ()->getVector ());
112+ }
113+
102114 protected function createAttributeAware ()
103115 {
104116 return $ this ->createEdge ();
Original file line number Diff line number Diff line change @@ -136,6 +136,32 @@ public function testRemoveInvalidEdge()
136136 $ this ->vertex ->removeEdge ($ edge );
137137 }
138138
139+ public function testRemoveWithEdgeLoopUndirected ()
140+ {
141+ // 1 -- 1
142+ $ edge = $ this ->vertex ->createEdge ($ this ->vertex );
143+
144+ $ this ->assertEquals (array (1 => $ this ->vertex ), $ this ->graph ->getVertices ()->getMap ());
145+
146+ $ this ->vertex ->destroy ();
147+
148+ $ this ->assertEquals (array (), $ this ->graph ->getVertices ()->getVector ());
149+ $ this ->assertEquals (array (), $ this ->graph ->getEdges ()->getVector ());
150+ }
151+
152+ public function testRemoveWithEdgeLoopDirected ()
153+ {
154+ // 1 --> 1
155+ $ edge = $ this ->vertex ->createEdgeTo ($ this ->vertex );
156+
157+ $ this ->assertEquals (array (1 => $ this ->vertex ), $ this ->graph ->getVertices ()->getMap ());
158+
159+ $ this ->vertex ->destroy ();
160+
161+ $ this ->assertEquals (array (), $ this ->graph ->getVertices ()->getVector ());
162+ $ this ->assertEquals (array (), $ this ->graph ->getEdges ()->getVector ());
163+ }
164+
139165 protected function createAttributeAware ()
140166 {
141167 return new Vertex (new Graph (), 1 );
You can’t perform that action at this time.
0 commit comments