Beispiel #1
0
        public void DijkstraTest()
        {
            Dijkstra g = new Dijkstra();

            g.AddVertex("A", new Dictionary <string, int>()
            {
                { "B", 7 }, { "C", 8 }
            });
            g.AddVertex("B", new Dictionary <string, int>()
            {
                { "A", 7 }, { "F", 2 }
            });
            //g.AddVertex("B", new Dictionary<string, int>() { { "F", 2 } });
            g.AddVertex("C", new Dictionary <string, int>()
            {
                { "A", 8 }, { "F", 6 }, { "G", 4 }
            });
            g.AddVertex("D", new Dictionary <string, int>()
            {
                { "F", 8 }
            });
            g.AddVertex("E", new Dictionary <string, int>()
            {
                { "H", 1 }
            });
            g.AddVertex("F", new Dictionary <string, int>()
            {
                { "B", 2 }, { "C", 6 }, { "D", 8 }, { "G", 9 }, { "H", 3 }
            });
            g.AddVertex("G", new Dictionary <string, int>()
            {
                { "C", 4 }, { "F", 9 }
            });
            g.AddVertex("H", new Dictionary <string, int>()
            {
                { "E", 1 }, { "F", 3 }
            });

            StringBuilder sb = new StringBuilder();

            g.FindShortestPath("A", "H").ForEach(x => sb.Insert(0, x));
            var dst = sb.ToString();
            var src = "BFH";

            Assert.AreEqual(src, dst);

            Dijkstra <Entity> g2 = new Dijkstra <Entity>();
            //Host h1 = new Host();
            //h1.SetIpAddress(IPAddress.Parse("10.0.0.1"));

            StringBuilder sb2 = new StringBuilder();
            //g2.FindShortestPath("A", "H").ForEach(x => sb2.Insert(0, x));
            var dst2 = sb2.ToString();
            var src2 = "BFH";

            Assert.AreEqual(src2, dst2);
        }