Exemplo n.º 1
0
            public void TestDeleteNode()
            {
                Graph gr = new Graph();

                Assert.AreEqual(0, gr.InsertNode());
                Assert.AreEqual(1, gr.InsertNode());
                Assert.AreEqual(2, gr.InsertNode());
                gr.InsertEdge(0, 1);
                gr.InsertEdge(1, 2);
                gr.InsertEdge(2, 0);
                gr.DeleteNode(0);

                Assert.AreEqual(1, gr.OutEdgeCount(1));
                Assert.AreEqual(0, gr.OutEdgeCount(2));

                // Trigger the exception - shouldn't be a zero node any more...
                gr.FindNode(0);
            }
Exemplo n.º 2
0
            public void TestDeleteEdge()
            {
                Graph gr = new Graph();

                Assert.AreEqual(0, gr.InsertNode());
                Assert.AreEqual(1, gr.InsertNode());
                Assert.AreEqual(2, gr.InsertNode());
                gr.InsertEdge(0, 1);
                gr.InsertEdge(1, 2);
                gr.InsertEdge(2, 0);
                gr.DeleteEdge(1, 2);
                Assert.AreEqual(1, gr.OutEdgeCount(0));
                Assert.AreEqual(0, gr.OutEdgeCount(1));
                Assert.AreEqual(1, gr.OutEdgeCount(2));

                // Trigger the exception - no edge from 1 to 0...
                gr.DeleteEdge(1, 0);
            }
Exemplo n.º 3
0
            public void TestInsertEdge()
            {
                object attr;
                Graph  gr     = new Graph();
                int    idFrom = gr.InsertNode(0);
                int    idTo   = gr.InsertNode(1);

                gr.InsertEdge(idFrom, idTo, 100);
                Assert.AreEqual(gr.OutEdgeCount(idFrom), 1);
                Assert.AreEqual(gr.OutEdgeCount(idTo), 0);
                int idEdge = gr.GetOutEdge(idFrom, 0, out attr);

                Assert.AreEqual(100, (int)attr);
                Assert.AreEqual(idTo, idEdge);

                // Try inserting the same edge twice to trigger exception...
                gr.InsertEdge(0, 1, 200);
            }
Exemplo n.º 4
0
        public void TestInsertEdge()
        {
            object attr;
            var    gr     = new Graph();
            var    idFrom = gr.InsertVertex(0);
            var    idTo   = gr.InsertVertex(1);

            gr.AddEdge(idFrom, idTo, 100);
            Assert.AreEqual(gr.OutEdgeCount(idFrom), 1);
            Assert.AreEqual(gr.OutEdgeCount(idTo), 0);
            var idEdge = gr.GetOutEdge(idFrom, 0, out attr);

            Assert.AreEqual(100, (int)attr);
            Assert.AreEqual(idTo, idEdge);

            // Try inserting the same edge twice to trigger exception...
            Assert.Throws(typeof(VfException), () => gr.AddEdge(0, 1, 200));
        }
Exemplo n.º 5
0
        public void TestDeleteVertex()
        {
            var gr = new Graph();

            Assert.AreEqual(0, gr.InsertVertex());
            Assert.AreEqual(1, gr.InsertVertex());
            Assert.AreEqual(2, gr.InsertVertex());
            gr.AddEdge(0, 1);
            gr.AddEdge(1, 2);
            gr.AddEdge(2, 0);
            gr.DeleteVertex(0);

            Assert.AreEqual(1, gr.OutEdgeCount(1));
            Assert.AreEqual(0, gr.OutEdgeCount(2));

            // Trigger the exception - shouldn't be a zero vertex any more...
            Assert.Throws(typeof(VfException), () => gr.FindVertex(0));
        }
Exemplo n.º 6
0
        public void TestDeleteEdge()
        {
            var gr = new Graph();

            Assert.AreEqual(0, gr.InsertVertex());
            Assert.AreEqual(1, gr.InsertVertex());
            Assert.AreEqual(2, gr.InsertVertex());
            gr.AddEdge(0, 1);
            gr.AddEdge(1, 2);
            gr.AddEdge(2, 0);
            gr.DeleteEdge(1, 2);
            Assert.AreEqual(1, gr.OutEdgeCount(0));
            Assert.AreEqual(0, gr.OutEdgeCount(1));
            Assert.AreEqual(1, gr.OutEdgeCount(2));

            // Trigger the exception - no edge from 1 to 0...
            Assert.Throws(typeof(VfException), () => gr.DeleteEdge(1, 0));
        }