AddVertices ( IGraph oGraph, Int32 iVerticesToAdd ) { Debug.Assert(oGraph != null); Debug.Assert(iVerticesToAdd >= 0); IVertex[] aoVertices = new IVertex[iVerticesToAdd]; IVertexCollection oVertexCollection = oGraph.Vertices; // Add the vertices. for (Int32 i = 0; i < iVerticesToAdd; i++) { IVertex oVertex = aoVertices[i] = new Vertex(); oVertex.Name = oVertex.ID.ToString(); oVertexCollection.Add(oVertex); } return (aoVertices); }
SetUp() { IVertex oVertex1 = new Vertex(); IVertex oVertex2 = new Vertex(); IGraph oGraph = new Graph(); oGraph.Vertices.Add(oVertex1); oGraph.Vertices.Add(oVertex2); m_oEdge = new Edge(oVertex1, oVertex2, true); m_oEdgeEventArgs = new EdgeEventArgs(m_oEdge); }
TestConstructor() { IVertex oHeadVertex = new Vertex(); IVertex oLeafVertex1 = new Vertex(); IVertex oLeafVertex2 = new Vertex(); FanMotif oFanMotif = new FanMotif( oHeadVertex, new IVertex[] {oLeafVertex1, oLeafVertex2} ); Assert.AreEqual(oHeadVertex, oFanMotif.HeadVertex); Assert.AreEqual(2, oFanMotif.LeafVertices.Length); Assert.AreEqual( oLeafVertex1, oFanMotif.LeafVertices[0] ); Assert.AreEqual( oLeafVertex2, oFanMotif.LeafVertices[1] ); Assert.AreEqual(1.0, oFanMotif.ArcScale); }
TestConstructor() { IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); IVertex oAnchorVertex3 = new Vertex(); DConnectorMotif o2ConnectorMotif = new DConnectorMotif( new List<IVertex>(){oAnchorVertex1, oAnchorVertex2}); Assert.AreEqual(oAnchorVertex1, o2ConnectorMotif.AnchorVertices[0]); Assert.AreEqual(oAnchorVertex2, o2ConnectorMotif.AnchorVertices[1]); DConnectorMotif o3ConnectorMotif = new DConnectorMotif( new List<IVertex>(){oAnchorVertex1, oAnchorVertex2, oAnchorVertex3}); Assert.AreEqual(oAnchorVertex1, o3ConnectorMotif.AnchorVertices[0]); Assert.AreEqual(oAnchorVertex2, o3ConnectorMotif.AnchorVertices[1]); Assert.AreEqual(oAnchorVertex3, o3ConnectorMotif.AnchorVertices[2]); Assert.AreEqual(0, o2ConnectorMotif.SpanVertices.Count); Assert.AreEqual(0, o3ConnectorMotif.SpanVertices.Count); Assert.AreEqual(1.0, o3ConnectorMotif.SpanScale); }
Add() { AssertValid(); IVertex oVertex = new Vertex(); this.Add(oVertex); AssertValid(); return (oVertex); }
TestClone ( Boolean bCopyMetadataValues, Boolean bCopyTag ) { // Create N objects, set random metadata and Tag on each object, clone // each object, check new object. const Int32 Vertices = 1000; Vertex [] aoVertices = new Vertex[Vertices]; // Set random values on each object. for (Int32 i = 0; i < Vertices; i++) { Vertex oVertex = aoVertices[i] = new Vertex(); MetadataUtil.SetRandomMetadata(oVertex, true, true, i); oVertex.Name = oVertex.ID.ToString(); } for (Int32 i = 0; i < Vertices; i++) { // Clone the object. Vertex oVertex = aoVertices[i]; Vertex oNewVertex = (Vertex)oVertex.Clone( bCopyMetadataValues, bCopyTag); // Check the metadata on the new object. MetadataUtil.CheckRandomMetadata( oNewVertex, bCopyMetadataValues, bCopyTag, i); // Check the name and ID on the new object. Assert.AreEqual(oVertex.Name, oNewVertex.Name); Assert.AreNotEqual(oVertex.ID, oNewVertex.ID); } }
TestAddBad8() { // Second vertex not in graph. try { IVertex [] aoVertices = AddVertices(1); IVertex oNonContainedVertex = new Vertex(); IEdge oEdge = new MockEdge( aoVertices[0], oNonContainedVertex, false, false, 2); m_oEdgeCollection.Add(oEdge); } catch (ArgumentException oArgumentException) { Assert.AreEqual( "Smrf.NodeXL.Core." + "EdgeCollection.Add: The edge is invalid.\r\n" + "Parameter name: edge" , oArgumentException.Message ); Assert.IsNotNull(oArgumentException.InnerException); Assert.AreEqual( "Smrf.NodeXL.Core." + "EdgeCollection.Add: The edge's second vertex does not" + " belong to a graph." , oArgumentException.InnerException.Message ); throw oArgumentException; } }
TestAdd4_Bad4() { // Second vertex not in graph. try { InitializeGraph(GraphDirectedness.Undirected); IVertex [] aoVertices = AddVertices(1); IVertex oNonContainedVertex = new Vertex(); m_oEdgeCollection.Add(aoVertices[0], oNonContainedVertex); } catch (ArgumentException oArgumentException) { Assert.AreEqual( "Smrf.NodeXL.Core." + "EdgeCollection.Add: One of the vertices is not" + " contained in this graph.\r\n" + "Parameter name: vertex2" , oArgumentException.Message ); throw oArgumentException; } }
TestContainsAndFind ( Int32 iVerticesToAdd ) { // Add the vertices. IVertex[] aoContainedVertices = AddVertices(iVerticesToAdd); // Create a vertex but don't add it. IVertex oNonContainedVertex = new Vertex(); oNonContainedVertex.Name = "ekdjrmnek"; IVertex oFoundVertex; // The collection should not contain oNonContainedVertex. Assert.IsFalse( m_oVertexCollection.Contains(oNonContainedVertex) ); Assert.IsFalse( m_oVertexCollection.Contains(oNonContainedVertex.ID) ); Assert.IsFalse( m_oVertexCollection.Find( oNonContainedVertex.ID, out oFoundVertex) ); Assert.IsNull(oFoundVertex); Assert.IsFalse( m_oVertexCollection.Contains(oNonContainedVertex.Name) ); Assert.IsFalse( m_oVertexCollection.Find( oNonContainedVertex.Name, out oFoundVertex) ); Assert.IsNull(oFoundVertex); // The collection should contain the vertices in aoContainedVertices. foreach (IVertex oContainedVertex in aoContainedVertices) { Assert.IsTrue( m_oVertexCollection.Contains(oContainedVertex) ); Assert.IsTrue( m_oVertexCollection.Contains(oContainedVertex.ID) ); Assert.IsTrue( m_oVertexCollection.Find( oContainedVertex.ID, out oFoundVertex) ); Assert.AreEqual(oFoundVertex, oContainedVertex); Assert.IsTrue( m_oVertexCollection.Contains(oContainedVertex.Name) ); Assert.IsTrue( m_oVertexCollection.Find( oContainedVertex.Name, out oFoundVertex) ); Assert.AreEqual(oFoundVertex, oContainedVertex); } }
AddVertices ( Int32 iVerticesToAdd ) { Debug.Assert(iVerticesToAdd >= 0); IVertex[] aoVertices = new IVertex[iVerticesToAdd]; // Add the vertices. for (Int32 i = 0; i < iVerticesToAdd; i++) { IVertex oVertex = aoVertices[i] = new Vertex(); oVertex.Name = i.ToString(); m_bVertexAdded = false; m_oAddedVertex = null; m_oVertexCollection.Add(oVertex); Assert.IsTrue(m_bVertexAdded); Assert.AreEqual(oVertex, m_oAddedVertex); } return (aoVertices); }
EdgeToVertices ( IEdge oEdge, String sMethodName, String sArgumentName, out Vertex oVertex1, out Vertex oVertex2 ) { AssertValid(); Debug.Assert( !String.IsNullOrEmpty(sMethodName) ); Debug.Assert( !String.IsNullOrEmpty(sArgumentName) ); oVertex1 = null; oVertex2 = null; ArgumentChecker oArgumentChecker = this.ArgumentChecker; // Check for null. oArgumentChecker.CheckArgumentNotNull( sMethodName, sArgumentName, oEdge); try { // Get the edge's vertices as IVertex interfaces. IVertex oVertexA = null, oVertexB = null; EdgeUtil.EdgeToVertices(oEdge, this.ClassName, sMethodName, out oVertexA, out oVertexB); // Cast the IVertex interfaces to Vertex, checking the types in the // process. oVertex1 = IVertexToVertex(oVertexA, sMethodName); oVertex2 = IVertexToVertex(oVertexB, sMethodName); } catch (ApplicationException oApplicationException) { // Change to an ArgumentException so the caller knows the source // of the problem. oArgumentChecker.ThrowArgumentException(sMethodName, sArgumentName, "The edge is invalid.", oApplicationException ); } }
RemoveFromGroup ( IEdge oEdge, Vertex oVertex ) { AssertValid(); Debug.Assert(oEdge != null); Debug.Assert(oVertex != null); LinkedListNode<IEdge> oNodeToRemove = null; // Loop through the vertex's group of incident edges. LinkedListNode<IEdge> oOldFirstIncidentEdgeNode = oVertex.FirstIncidentEdgeNode; for ( LinkedListNode<IEdge> oNode = oOldFirstIncidentEdgeNode; oNode != null && oNode.Value != null; oNode = oNode.Next ) { if (oNode.Value == oEdge) { oNodeToRemove = oNode; break; } } if (oNodeToRemove == null) { // The edge wasn't found. return (false); } LinkedListNode<IEdge> oPreviousNode = oNodeToRemove.Previous; LinkedListNode<IEdge> oNextNode = oNodeToRemove.Next; Debug.Assert(oNextNode != null); // Remove the node. m_oLinkedList.Remove(oNodeToRemove); if (oOldFirstIncidentEdgeNode != oNodeToRemove) { // Nothing more needs to be done. return (true); } // The vertex's first node was removed, so its FirstIncidentEdgeNode // property needs to be set with a new first node. LinkedListNode<IEdge> oNewFirstIncidentEdgeNode; if (oNextNode.Value != null) { // The next node belongs to the vertex's group of incident edges // and is not the group's null terminator. oNewFirstIncidentEdgeNode = oNextNode; } else { // The next node is the null terminator for the vertex's group of // incident edges, which means that the vertex has no more incident // edges. Remove the null terminator. m_oLinkedList.Remove(oNextNode); oNewFirstIncidentEdgeNode = null; } oVertex.FirstIncidentEdgeNode = oNewFirstIncidentEdgeNode; return (true); }
AddToGroup ( IEdge oEdge, Vertex oVertex ) { AssertValid(); Debug.Assert(oEdge != null); Debug.Assert(oVertex != null); // Get the vertex's first incident edge. LinkedListNode<IEdge> oFirstIncidentEdgeNode = oVertex.FirstIncidentEdgeNode; // Create a node for the new edge. LinkedListNode<IEdge> oNewNode = new LinkedListNode<IEdge>(oEdge); if (oFirstIncidentEdgeNode != null) { // Add the new node before the vertex's first node. m_oLinkedList.AddBefore(oFirstIncidentEdgeNode, oNewNode); } else { // The vertex has no nodes. Create a group for the vertex. The // group consists of the new node followed by a null terminator. m_oLinkedList.AddFirst( new LinkedListNode<IEdge>(null) ); m_oLinkedList.AddFirst(oNewNode); } // The new node is now the first node for the vertex. oVertex.FirstIncidentEdgeNode = oNewNode; }
GetDegree ( Vertex oVertex ) { AssertValid(); Debug.Assert(oVertex != null); // Loop through the vertex's group of incident edges. Int32 iDegree = 0; for ( LinkedListNode<IEdge> oNode = oVertex.FirstIncidentEdgeNode; oNode != null && oNode.Value != null; oNode = oNode.Next ) { iDegree++; } return (iDegree); }
RemoveAllFromGroup ( Vertex oVertex ) { AssertValid(); Debug.Assert(oVertex != null); String sClassName = this.ClassName; const String MethodName = "RemoveAllFromGroup"; // Loop through the vertex's group of incident edges. LinkedListNode<IEdge> oNode = oVertex.FirstIncidentEdgeNode; while (oNode != null) { IEdge oEdge = oNode.Value; if (oEdge == null) { // The node is the null terminator. Remove it. m_oLinkedList.Remove(oNode); break; } // Get the edge's adjacent vertices. Vertex oVertex1, oVertex2; Edge.EdgeToVertices( oEdge, sClassName, MethodName, out oVertex1, out oVertex2); Debug.Assert(oVertex1 == oVertex || oVertex2 == oVertex); // Figure out which of the adjacent vertices is not oVertex. Vertex oAdjacentVertex = null; if (oVertex1 == oVertex) { oAdjacentVertex = oVertex2; } else if (oVertex2 == oVertex) { oAdjacentVertex = oVertex1; } else { // This should never occur. Debug.Assert(false); throw new ApplicationException( String.Format( "{0}.{1}: An incident edge does not connect to the" + " specified vertex." , sClassName, MethodName ) ); } // Remove the edge from the adjacent Vertex's group of incident // edges. if ( !oEdge.IsSelfLoop && !RemoveFromGroup(oEdge, oAdjacentVertex) ) { // This should never occur. Debug.Assert(false); throw new ApplicationException( String.Format( "{0}.{1}: An incident edge could not be removed from an" + " adjacent vertex's group of incident edges." , sClassName, MethodName ) ); } // Remove the edge from oVertex's group of incident edges. LinkedListNode<IEdge> oNodeToRemove = oNode; oNode = oNode.Next; m_oLinkedList.Remove(oNodeToRemove); OnEdgeRemoved(oEdge, false); } // The vertex no longer has any incident edges. oVertex.FirstIncidentEdgeNode = null; AssertValid(); }
GetPredecessorOrSuccessorVertices ( Vertex oVertex, Boolean bIncludePredecessor, Boolean bIncludeSuccessor ) { AssertValid(); Debug.Assert(oVertex != null); const String MethodName = "GetPredecessorOrSuccessorVertices"; // If two edges connect this vertex to another vertex, the other vertex // should not be counted twice. To prevent this, use a dictionary to // collect the vertices and check the dictionary before adding a vertex // to it. // // The dictionary key is the vertex ID and the value is the vertex. Dictionary<Int32, IVertex> oPredecessorOrSuccessorVertices = new Dictionary<Int32, IVertex>(); // Loop through the vertex's group of incident edges. for ( LinkedListNode<IEdge> oNode = oVertex.FirstIncidentEdgeNode; oNode != null && oNode.Value != null; oNode = oNode.Next ) { IEdge oEdge = oNode.Value; // Get the edge's vertices. IVertex oVertex1, oVertex2; EdgeUtil.EdgeToVertices(oEdge, this.ClassName, MethodName, out oVertex1, out oVertex2); Debug.Assert(oVertex1 == oVertex || oVertex2 == oVertex); // Determine whether the adjacent vertex should be included in the // returned collection. IVertex oAdjacentVertex = null; if (oEdge.IsDirected) { // oVertex1 is the back vertex. oVertex2 is the front vertex. if (bIncludePredecessor) { if (oVertex2 == oVertex) { oAdjacentVertex = oVertex1; } } if (bIncludeSuccessor) { // oVertex1 is the back vertex. if (oVertex1 == oVertex) { oAdjacentVertex = oVertex2; } } } else { // The edge is undirected. if (oVertex1 == oVertex) { oAdjacentVertex = oVertex2; } else { Debug.Assert(oVertex2 == oVertex); oAdjacentVertex = oVertex1; } } // If there is an adjacent vertex, make sure it hasn't already been // added to the dictionary. if ( oAdjacentVertex != null && !oPredecessorOrSuccessorVertices.ContainsKey( oAdjacentVertex.ID) ) { oPredecessorOrSuccessorVertices.Add( oAdjacentVertex.ID, oAdjacentVertex); } } // Convert the dictionary values to an array. Dictionary<Int32, IVertex>.ValueCollection oValueCollection = oPredecessorOrSuccessorVertices.Values; Int32 iValues = oValueCollection.Count; IVertex [] aoPredecessorOrSuccessorVertices = new IVertex[iValues]; oValueCollection.CopyTo(aoPredecessorOrSuccessorVertices, 0); oPredecessorOrSuccessorVertices.Clear(); return (aoPredecessorOrSuccessorVertices); }
TestVertexAdded() { const Int32 Vertices = 2000; for (Int32 i = 0; i < Vertices; i++) { IVertex oVertex = new Vertex(); m_bVertexAdded = false; m_oAddedVertex = null; m_oGraph.Vertices.Add(oVertex); Assert.IsTrue(m_bVertexAdded); Assert.AreEqual(oVertex, m_oAddedVertex); } }
EdgeToVertices ( IEdge oEdge, String sClassName, String sMethodOrPropertyName, out Vertex oVertex1, out Vertex oVertex2 ) { Debug.Assert( !String.IsNullOrEmpty(sClassName) ); Debug.Assert( !String.IsNullOrEmpty(sMethodOrPropertyName) ); // Cast to an Edge. Edge oEdge2 = IEdgeToEdge(oEdge, sClassName, sMethodOrPropertyName); // Cast the IVertex interfaces to Vertex, checking the types in the // process. oVertex1 = Vertex.IVertexToVertex( oEdge2.m_oVertex1, sClassName, sMethodOrPropertyName); oVertex2 = Vertex.IVertexToVertex( oEdge2.m_oVertex2, sClassName, sMethodOrPropertyName); }
TestRemove() { // Vertex not in collection. const Int32 Vertices = 65; // Add the vertices and edges. IVertex[] aoVertices = AddVertices(Vertices); TestGraphUtil.MakeGraphComplete(m_oGraph, aoVertices, false); // Check the number of vertices and edges. Assert.AreEqual(Vertices, m_oVertexCollection.Count); Int32 iEdges = m_oGraph.Edges.Count; Assert.AreEqual( TestGraphUtil.GetEdgeCountForCompleteGraph(Vertices), iEdges ); // Attempt to remove a vertex not in the collection. IVertex oVertex = new Vertex(); Boolean bRemoved = m_oVertexCollection.Remove(oVertex); Assert.IsFalse(bRemoved); bRemoved = m_oVertexCollection.Remove(oVertex.ID); Assert.IsFalse(bRemoved); bRemoved = m_oVertexCollection.Remove("abc"); Assert.IsFalse(bRemoved); // Check the number of vertices and edges. Assert.AreEqual(Vertices, m_oVertexCollection.Count); Assert.AreEqual(iEdges, m_oGraph.Edges.Count); }
SetUp() { m_oVertex = new Vertex(); m_oVertexEventArgs = new VertexEventArgs(m_oVertex); }
AddLoadedVertex ( String sVertexName, IVertexCollection oVertices, Dictionary<Int32, IVertex> oVertexDictionary ) { Debug.Assert( !String.IsNullOrEmpty(sVertexName) ); Debug.Assert(oVertices != null); Debug.Assert(oVertexDictionary != null); AssertValid(); IVertex oVertex = new Vertex(); oVertex.Name = sVertexName; oVertices.Add(oVertex); oVertexDictionary.Add(oVertices.Count - 1, oVertex); }
TestAddBad2() { // Vertex already added to collection. IVertex oVertex = new Vertex(); m_oVertexCollection.Add(oVertex); try { m_oVertexCollection.Add(oVertex); } catch (ArgumentException oArgumentException) { Assert.AreEqual( "Smrf.NodeXL.Core." + "VertexCollection.Add: The vertex already belongs to a" + " graph. A vertex can't be added twice.\r\n" + "Parameter name: vertex" , oArgumentException.Message ); throw oArgumentException; } }
TestGetConnectingEdgesBad4() { // Second vertex not in graph. try { IVertex [] aoVertices = AddVertices(1); IVertex oNonContainedVertex = new Vertex(); ICollection<IEdge> oConnectingEdges = m_oEdgeCollection.GetConnectingEdges( aoVertices[0], oNonContainedVertex ); } catch (ArgumentException oArgumentException) { Assert.AreEqual( "Smrf.NodeXL.Core." + "EdgeCollection.GetConnectingEdges: One of the vertices is" + " not contained in this graph.\r\n" + "Parameter name: vertex2" , oArgumentException.Message ); throw oArgumentException; } }
TestSpanVertices() { IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List<IVertex>() { oAnchorVertex1, oAnchorVertex2 }); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); Assert.AreEqual(2, oDConnectorMotif.SpanVertices.Count); Assert.AreEqual( oSpanVertex1, oDConnectorMotif.SpanVertices[0] ); Assert.AreEqual( oSpanVertex2, oDConnectorMotif.SpanVertices[1] ); }
TestAdd3_Bad3() { // First vertex not in graph. try { IVertex [] aoVertices = AddVertices(1); IVertex oNonContainedVertex = new Vertex(); m_oEdgeCollection.Add(oNonContainedVertex, aoVertices[0], false); } catch (ArgumentException oArgumentException) { Assert.AreEqual( "Smrf.NodeXL.Core.EdgeCollection.Add:" + " One of the vertices is not" + " contained in this graph.\r\n" + "Parameter name: vertex1" , oArgumentException.Message ); throw oArgumentException; } }
TestAllVertices() { IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List<IVertex>() {oAnchorVertex1, oAnchorVertex2} ); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); IVertex[] aoVerticesInMotif = oDConnectorMotif.VerticesInMotif; // Note that the anchor vertices aren't actually a part of the motif. Assert.AreEqual(2, aoVerticesInMotif.Length); Assert.AreEqual( oSpanVertex1, aoVerticesInMotif.Single( oVertex => oVertex == oSpanVertex1) ); Assert.AreEqual( oSpanVertex2, aoVerticesInMotif.Single( oVertex => oVertex == oSpanVertex2) ); }
SetUp() { m_oVertex = new Vertex(); }
TestCollapsedAttributes() { // With vertex names. IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); oAnchorVertex1.Name = "Name1"; oAnchorVertex2.Name = "Name2"; DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List<IVertex>(){oAnchorVertex1, oAnchorVertex2} ); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); String sCollapsedAttributes = oDConnectorMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual( CollapsedGroupAttributeValues.DConnectorMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type] ); Assert.AreEqual( "2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.AnchorVertices] ); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0) ) ); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1))); Assert.AreEqual( "Name1", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0)]); Assert.AreEqual( "Name2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1)]); Assert.AreEqual( "2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.SpanVertices] ); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.SpanScale) ); Assert.AreEqual( "1", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.SpanScale] ); }
AddVertices ( params String [] asVertexNames ) { Dictionary<String, IVertex> oVertexDictionary = new Dictionary<String, IVertex>(asVertexNames.Length); foreach (String sVertexName in asVertexNames) { IVertex oVertex = new Vertex(); oVertex.Name = sVertexName; m_oVertices.Add(oVertex); oVertexDictionary.Add(sVertexName, oVertex); } return (oVertexDictionary); }
TestCollapsedAttributes2() { // Without vertex names and with SpanScale set to a non-default value. IVertex oAnchorVertex1 = new Vertex(); IVertex oAnchorVertex2 = new Vertex(); DConnectorMotif oDConnectorMotif = new DConnectorMotif( new List<IVertex>() {oAnchorVertex1, oAnchorVertex2} ); IVertex oSpanVertex1 = new Vertex(); IVertex oSpanVertex2 = new Vertex(); oDConnectorMotif.SpanVertices.Add(oSpanVertex1); oDConnectorMotif.SpanVertices.Add(oSpanVertex2); oDConnectorMotif.SpanScale = 0.5; String sCollapsedAttributes = oDConnectorMotif.CollapsedAttributes; CollapsedGroupAttributes oCollapsedGroupAttributes = CollapsedGroupAttributes.FromString(sCollapsedAttributes); Assert.AreEqual( CollapsedGroupAttributeValues.DConnectorMotifType, oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.Type] ); Assert.AreEqual( "2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.AnchorVertices] ); Assert.IsFalse( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(0) ) ); Assert.IsFalse( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.GetAnchorVertexNameKey(1) ) ); Assert.AreEqual( "2", oCollapsedGroupAttributes[ CollapsedGroupAttributeKeys.SpanVertices] ); Assert.IsTrue( oCollapsedGroupAttributes.ContainsKey( CollapsedGroupAttributeKeys.SpanScale) ); Assert.AreEqual( "0.5", oCollapsedGroupAttributes[CollapsedGroupAttributeKeys.SpanScale] ); }