//************************************************************************* // Method: TestRemove() // /// <summary> /// Tests a Remove() method. /// </summary> /// /// <param name="iVerticesToAdd"> /// Number of vertices to add. /// </param> /// /// <param name="aiIndexesOfEdgesToRemove"> /// Array of indexes of the edges to remove. /// </param> /// /// <param name="eRemoveOverload"> /// Specifies which overload of Remove() to call. /// </param> //************************************************************************* protected void TestRemove( Int32 iVerticesToAdd, Int32 [] aiIndexesOfEdgesToRemove, RemoveOverload eRemoveOverload ) { Debug.Assert(iVerticesToAdd >= 0); Debug.Assert(aiIndexesOfEdgesToRemove != null); Debug.Assert( Enum.IsDefined(typeof(RemoveOverload), eRemoveOverload) ); // Remove any existing edges. m_oEdgeCollection.Clear(); // Add the vertices and edges. IEdge [] aoEdges = AddEdges( iVerticesToAdd, GraphDirectedness.Directed, AddOverload.IEdge); Int32 iEdges = aoEdges.Length; // Check the number of edges. Assert.AreEqual(iEdges, m_oEdgeCollection.Count); // Remove the specified edges. Int32 iEdgesToRemove = aiIndexesOfEdgesToRemove.Length; for (Int32 i = 0; i < iEdgesToRemove; i++) { IEdge oEdgeToRemove = aoEdges[ aiIndexesOfEdgesToRemove[i] ]; Boolean bRemoved = false; m_bEdgeRemoved = false; m_oRemovedEdge = null; switch (eRemoveOverload) { case RemoveOverload.ByReference: bRemoved = m_oEdgeCollection.Remove(oEdgeToRemove); break; case RemoveOverload.ByID: bRemoved = m_oEdgeCollection.Remove(oEdgeToRemove.ID); break; case RemoveOverload.ByName: bRemoved = m_oEdgeCollection.Remove(oEdgeToRemove.Name); break; default: Debug.Assert(false); break; } Assert.IsTrue(bRemoved); Assert.IsTrue(m_bEdgeRemoved); Assert.AreEqual(oEdgeToRemove, m_oRemovedEdge); } // Check the number of edges. Int32 iRemainingEdges = iEdges - iEdgesToRemove; Assert.AreEqual(iRemainingEdges, m_oEdgeCollection.Count); // Verify that the correct edges are still in the collection. for (Int32 i = 0; i < iEdges; i++) { Boolean bContains = m_oEdgeCollection.Contains( aoEdges[i] ); if (Array.IndexOf(aiIndexesOfEdgesToRemove, i) >= 0) { // i is in aiIndexesOfEdgesToRemove, so aiEdges[i] should not // be in the collection. Assert.IsFalse(bContains); } else { Assert.IsTrue(bContains); } } }
//************************************************************************* // Method: TestRemove() // /// <summary> /// Tests a Remove() method. /// </summary> /// /// <param name="iVerticesToAdd"> /// Number of vertices to add. /// </param> /// /// <param name="aiIndexesOfVerticesToRemove"> /// Array of indexes of the vertices to remove. /// </param> /// /// <param name="eRemoveOverload"> /// Specifies which overload of Remove() to call. /// </param> //************************************************************************* protected void TestRemove( Int32 iVerticesToAdd, Int32 [] aiIndexesOfVerticesToRemove, RemoveOverload eRemoveOverload ) { Debug.Assert(iVerticesToAdd >= 0); Debug.Assert(aiIndexesOfVerticesToRemove != null); Debug.Assert( Enum.IsDefined(typeof(RemoveOverload), eRemoveOverload) ); // Remove any existing vertices and edges. m_oVertexCollection.Clear(); m_oGraph.Edges.Clear(); // Add the vertices and edges. IVertex[] aoVertices = AddVertices(iVerticesToAdd); TestGraphUtil.MakeGraphComplete(m_oGraph, aoVertices, false); // Check the number of vertices and edges. Assert.AreEqual(iVerticesToAdd, m_oVertexCollection.Count); Assert.AreEqual( TestGraphUtil.GetEdgeCountForCompleteGraph(iVerticesToAdd), m_oGraph.Edges.Count ); // Remove the specified vertices. Int32 iVerticesToRemove = aiIndexesOfVerticesToRemove.Length; for (Int32 i = 0; i < iVerticesToRemove; i++) { IVertex oVertexToRemove = aoVertices[ aiIndexesOfVerticesToRemove[i] ]; Boolean bRemoved = false; m_bVertexRemoved = false; m_oRemovedVertex = null; switch (eRemoveOverload) { case RemoveOverload.ByReference: bRemoved = m_oVertexCollection.Remove(oVertexToRemove); break; case RemoveOverload.ByID: bRemoved = m_oVertexCollection.Remove(oVertexToRemove.ID); break; case RemoveOverload.ByName: bRemoved = m_oVertexCollection.Remove(oVertexToRemove.Name); break; default: Debug.Assert(false); break; } Assert.IsTrue(bRemoved); Assert.IsTrue(m_bVertexRemoved); Assert.AreEqual(oVertexToRemove, m_oRemovedVertex); Assert.IsNull(oVertexToRemove.ParentGraph); } // Check the number of vertices and edges. Int32 iRemainingVertices = iVerticesToAdd - iVerticesToRemove; Assert.AreEqual(iRemainingVertices, m_oVertexCollection.Count); Assert.AreEqual( TestGraphUtil.GetEdgeCountForCompleteGraph(iRemainingVertices), m_oGraph.Edges.Count ); // Verify that the correct vertices are still in the collection. for (Int32 i = 0; i < iVerticesToAdd; i++) { Boolean bContains = m_oVertexCollection.Contains( aoVertices[i] ); if (Array.IndexOf(aiIndexesOfVerticesToRemove, i) >= 0) { // i is in aiIndexesOfVerticesToRemove, so aoVertices[i] should // not be in the collection. Assert.IsFalse(bContains); } else { Assert.IsTrue(bContains); Assert.IsNotNull(aoVertices[i].ParentGraph); } } }