Пример #1
0
        public void TestGraphCreation()
        {
            Graph g = new GraphM(7);

            g.SetEdge(0, 1, 2);
            g.SetEdge(0, 2, 1);
            g.SetEdge(0, 3, 1);
            g.SetEdge(0, 4, 1);
            g.SetEdge(1, 5, 1);
            g.SetEdge(2, 5, 1);
            g.SetEdge(3, 6, 1);
            g.SetEdge(5, 4, 1);
            g.SetEdge(6, 4, 1);
            g.SetEdge(6, 5, 1);

            var edge = g.FirstEdge(0);

            Assert.IsTrue(g.IsEdge(edge));
            Assert.IsTrue(g.Weight(edge) == 2);
            Assert.AreEqual(g.EdgeNum(), 10);
        }
Пример #2
0
        public void Test_Dfs_Matrix_Directed()
        {
            Graph g = new GraphM(7);

            g.SetEdge(0, 1, 2);
            g.SetEdge(0, 2, 1);
            g.SetEdge(0, 3, 1);
            g.SetEdge(0, 4, 1);
            g.SetEdge(1, 5, 1);
            g.SetEdge(2, 5, 1);
            g.SetEdge(3, 6, 1);
            g.SetEdge(5, 4, 1);
            g.SetEdge(6, 4, 1);
            g.SetEdge(6, 5, 1);


            ITravel dfs = new Dfs(g, preVisit);

            dfs.Travel(0);
            Assert.AreEqual(10, g.EdgeNum());
            Assert.AreEqual("0154236", stringBuilder.ToString());
        }
Пример #3
0
        public void Test_Bfs_Matrix_Non_Directed()
        {
            Graph g = new GraphM(7, false);

            g.SetEdge(0, 1, 2);
            g.SetEdge(0, 2, 1);
            g.SetEdge(0, 3, 1);
            g.SetEdge(0, 4, 1);
            g.SetEdge(1, 5, 1);
            g.SetEdge(2, 5, 1);
            g.SetEdge(3, 6, 1);
            g.SetEdge(5, 4, 1);
            g.SetEdge(6, 4, 1);
            g.SetEdge(6, 5, 1);


            ITravel bfs = new Bfs(g, preVisit);

            bfs.Travel(0);
            Assert.AreEqual(10, g.EdgeNum());
            Assert.AreEqual("0123456", stringBuilder.ToString());
        }