TestMoveNext5()
        {
            // N vertices, connect each vertex to all other vertices.

            const Int32 Vertices = 100;

            // Add the vertices.

            IVertex[] aoVertices = AddVertices(Vertices);

            // Connect each vertex to all other vertices.

            IEdge[] aoAddedEdges =
                TestGraphUtil.MakeGraphComplete(m_oGraph, aoVertices, true);

            // Enumerate the edges using m_oEnumerator and compare the enumerated
            // edges with the edges that were added to the edge collection.

            EnumerateAndCompare(aoAddedEdges);

            // Reset the enumerator and repeat.

            m_oEnumerator.Reset();

            EnumerateAndCompare(aoAddedEdges);
        }
Пример #2
0
        TestLayOut()
        {
            const Int32 Vertices = 100;

            IGraph oGraph = new Graph();

            IVertex [] aoVertices = TestGraphUtil.AddVertices(oGraph, Vertices);

            TestGraphUtil.MakeGraphComplete(oGraph, aoVertices, false);

            // Initialize the vertex locations to impossible values.

            const Int32 ImpossibleCoordinate = Int32.MinValue;

            foreach (IVertex oVertex in aoVertices)
            {
                oVertex.Location = new Point(
                    ImpossibleCoordinate, ImpossibleCoordinate);
            }

            const Int32 Width  = 1000;
            const Int32 Height = 600;

            Rectangle oRectangle = new Rectangle(0, 0, Width, Height);

            LayoutContext oLayoutContext = new LayoutContext(oRectangle);

            m_oFruchtermanReingoldLayout.LayOutGraph(oGraph, oLayoutContext);

            foreach (IVertex oVertex in aoVertices)
            {
                PointF oLocation = oVertex.Location;

                Single fX = oLocation.X;

                Assert.AreNotEqual(fX, ImpossibleCoordinate);
                Assert.IsTrue(fX >= 0);
                Assert.IsTrue(fX <= Width);

                Single fY = oLocation.Y;

                Assert.AreNotEqual(fY, ImpossibleCoordinate);
                Assert.IsTrue(fY >= 0);
                Assert.IsTrue(fY <= Height);
            }
        }
Пример #3
0
        TestEdges()
        {
            Assert.IsNotNull(m_oGraph.Edges);
            Assert.IsInstanceOfType(m_oGraph.Edges, typeof(EdgeCollection));
            Assert.AreEqual(0, m_oGraph.Edges.Count);

            const Int32 Vertices = 100;

            IVertex [] aoVertices = TestGraphUtil.AddVertices(m_oGraph, Vertices);

            IEdge [] aoEdges =
                TestGraphUtil.MakeGraphComplete(m_oGraph, aoVertices, false);

            Assert.AreEqual(aoEdges.Length, m_oGraph.Edges.Count);

            foreach (IEdge oEdge in aoEdges)
            {
                Assert.IsTrue(m_oGraph.Edges.Contains(oEdge));
            }
        }
Пример #4
0
        TestClone()
        {
            // Loop through multiple scenarios.

            Int32 [] aiVertices = new Int32 [] { 0, 6 };

            foreach (Boolean bCopyMetadataValues in TestGraphUtil.AllBoolean)
            {
                foreach (Boolean bCopyTag in TestGraphUtil.AllBoolean)
                {
                    foreach (GraphDirectedness eDirectedness in
                             TestGraphUtil.AllGraphDirectedness)
                    {
                        foreach (Int32 iVertices in aiVertices)
                        {
                            foreach (Boolean bAddEdges in TestGraphUtil.AllBoolean)
                            {
                                const String Name = "fdjkerwuio";

                                // Prepare the graph to be cloned.

                                InitializeGraph(eDirectedness);

                                m_oGraph.Name = Name;

                                MetadataUtil.SetRandomMetadata(m_oGraph, true, true, m_oGraph.ID);

                                // Add the vertices and set metadata on them.  For the seed, use
                                // the vertex ID.

                                IVertex [] aoVertices =
                                    TestGraphUtil.AddVertices(m_oGraph, iVertices);

                                for (Int32 i = 0; i < iVertices; i++)
                                {
                                    IVertex oVertex = aoVertices[i];

                                    MetadataUtil.SetRandomMetadata(
                                        oVertex, true, true, oVertex.ID);
                                }

                                if (bAddEdges)
                                {
                                    // Add the edges and set metadata on them.  For the seed, use
                                    // the edge ID.

                                    IEdge [] aoEdges = TestGraphUtil.MakeGraphComplete(
                                        m_oGraph, aoVertices,
                                        (eDirectedness == GraphDirectedness.Directed)
                                        );

                                    foreach (IEdge oEdge in m_oGraph.Edges)
                                    {
                                        MetadataUtil.SetRandomMetadata(
                                            oEdge, true, true, oEdge.ID);
                                    }
                                }

                                // Clone the graph.

                                IGraph oNewGraph = m_oGraph.Clone(bCopyMetadataValues, bCopyTag);

                                // Check the metadata on the new graph.

                                MetadataUtil.CheckRandomMetadata(
                                    oNewGraph, bCopyMetadataValues, bCopyTag, m_oGraph.ID);

                                // Check the vertices on the new graph.

                                IVertexCollection oNewVertexCollection = oNewGraph.Vertices;

                                Assert.IsNotNull(oNewVertexCollection);

                                Assert.AreEqual(iVertices, oNewVertexCollection.Count);

                                // Loop through the original vertices.

                                foreach (IVertex oVertex in m_oGraph.Vertices)
                                {
                                    // Find the corresponding new vertex, by name.

                                    IVertex oNewVertex;

                                    Assert.IsTrue(oNewVertexCollection.Find(
                                                      oVertex.Name, out oNewVertex));

                                    Assert.AreNotEqual(oVertex.ID, oNewVertex.ID);

                                    // Check the vertex's metadata.  Use the original vertex ID as
                                    // a seed.

                                    MetadataUtil.CheckRandomMetadata(oNewVertex,
                                                                     bCopyMetadataValues, bCopyTag, oVertex.ID);
                                }

                                // Check the edges on the new graph.

                                IEdgeCollection oNewEdgeCollection = oNewGraph.Edges;

                                Assert.IsNotNull(oNewEdgeCollection);

                                Assert.AreEqual(

                                    bAddEdges ?
                                    TestGraphUtil.GetEdgeCountForCompleteGraph(iVertices) : 0,

                                    oNewEdgeCollection.Count
                                    );

                                // Loop through the original edges.

                                foreach (IEdge oEdge in m_oGraph.Edges)
                                {
                                    // Find the corresponding new edge, by name.

                                    IEdge oNewEdge;

                                    Assert.IsTrue(oNewEdgeCollection.Find(
                                                      oEdge.Name, out oNewEdge));

                                    Assert.AreNotEqual(oEdge.ID, oNewEdge.ID);

                                    // Check the edge's metadata.  Use the original edge ID as a
                                    // seed.

                                    MetadataUtil.CheckRandomMetadata(oNewEdge,
                                                                     bCopyMetadataValues, bCopyTag, oEdge.ID);

                                    // Verify that the new edge and original edge connect vertices
                                    // that correspond.

                                    Assert.IsNotNull(oNewEdge.Vertices[0]);
                                    Assert.IsNotNull(oNewEdge.Vertices[1]);

                                    Assert.AreEqual(oNewEdge.Vertices[0].Name,
                                                    oEdge.Vertices[0].Name);

                                    Assert.AreEqual(oNewEdge.Vertices[1].Name,
                                                    oEdge.Vertices[1].Name);
                                }

                                // Check the other properties on the new graph.

                                Assert.AreEqual(Name, oNewGraph.Name);

                                Assert.AreEqual(eDirectedness, oNewGraph.Directedness);

                                Assert.AreNotEqual(m_oGraph.ID, oNewGraph.ID);
                            }
                        }
                    }
                }
            }
        }