Ejemplo n.º 1
0
 public void TestBFS()
 {
     Graph g = new Graph(false, 6);
     g.Insert(1, 2);
     g.Insert(1, 5);
     g.Insert(1, 6);
     g.Insert(2, 3);
     g.Insert(2, 5);
     g.Insert(3, 4);
     g.Insert(5, 4);
     BFSResult bfsResult = g.BreadthFirstSearch(1);
     List<SearchResult> result = bfsResult.SearchResult.Where(l => l.Status == ProcessStatus.AfterProcessVertex).ToList<SearchResult>();
     Assert.AreEqual(1, result[0].Vertex);
     Assert.AreEqual(6, result[1].Vertex);
     Assert.AreEqual(5, result[2].Vertex);
     Assert.AreEqual(2, result[3].Vertex);
     Assert.AreEqual(4, result[4].Vertex);
     Assert.AreEqual(3, result[5].Vertex);
 }
Ejemplo n.º 2
0
        public void TestFindShortestRoute()
        {
            Graph g = new Graph(false, 6);
            g.Insert(1, 2);
            g.Insert(1, 5);
            g.Insert(1, 6);
            g.Insert(2, 3);
            g.Insert(2, 5);
            g.Insert(3, 4);
            g.Insert(5, 4);
            BFSResult bfsResult = g.BreadthFirstSearch(1);

            List<int> routeTo6 = g.FindPath(1, 6, bfsResult.Parents);
            Assert.AreEqual(1, routeTo6[0]);
            Assert.AreEqual(6, routeTo6[1]);

            List<int> routeTo5 = g.FindPath(1, 5, bfsResult.Parents);
            Assert.AreEqual(1, routeTo5[0]);
            Assert.AreEqual(5, routeTo5[1]);

            List<int> routeTo4 = g.FindPath(1, 4, bfsResult.Parents);
            Assert.AreEqual(1, routeTo4[0]);
            Assert.AreEqual(5, routeTo4[1]);
            Assert.AreEqual(4, routeTo4[2]);
        }