Beispiel #1
0
        public void testRoutePathsInNetwork()
        {
            Siec network = new Siec();

            List <Wezel>     nodes = new List <Wezel>();
            List <IPAddress> ips   = new List <IPAddress>();
            List <Lacze>     links = new List <Lacze>();

            ips.Add(IPAddress.Parse("127.0.0.2"));
            ips.Add(IPAddress.Parse("127.0.0.31"));
            ips.Add(IPAddress.Parse("127.0.0.17"));
            ips.Add(IPAddress.Parse("127.0.0.4"));
            ips.Add(IPAddress.Parse("127.0.0.33"));
            ips.Add(IPAddress.Parse("127.0.0.15"));
            ips.Add(IPAddress.Parse("127.0.0.6"));

            nodes.Add(new Wezel(2, "127.0.0.2"));
            nodes.Add(new Wezel(31, "127.0.0.31"));
            nodes.Add(new Wezel(17, "127.0.0.17"));
            nodes.Add(new Wezel(4, "127.0.0.4"));
            nodes.Add(new Wezel(33, "127.0.0.33"));
            nodes.Add(new Wezel(15, "127.0.0.15"));
            nodes.Add(new Wezel(6, "127.0.0.6"));

            //Dodawanie krawedzi
            links.Add(new Lacze(0, nodes[0], nodes[1], 1, 0));  //2-31
            links.Add(new Lacze(1, nodes[1], nodes[2], 1, 0));  //31-17
            links.Add(new Lacze(2, nodes[2], nodes[3], 1, 0));  //17-4
            links.Add(new Lacze(3, nodes[2], nodes[4], 1, 0));  //17-33
            links.Add(new Lacze(4, nodes[2], nodes[5], 1, 0));  //17-15
            links.Add(new Lacze(5, nodes[4], nodes[5], 1, 0));  //33-15
            links.Add(new Lacze(6, nodes[5], nodes[6], 1, 0));  //15-6

            links.Add(new Lacze(7, nodes[1], nodes[0], 1, 0));  //31-2
            links.Add(new Lacze(8, nodes[2], nodes[1], 1, 0));  //17-31
            links.Add(new Lacze(9, nodes[3], nodes[2], 1, 0));  //4-17
            links.Add(new Lacze(10, nodes[4], nodes[2], 1, 0)); //33-17
            links.Add(new Lacze(11, nodes[5], nodes[2], 1, 0)); //15-17
            links.Add(new Lacze(12, nodes[5], nodes[4], 1, 0)); //15-33
            links.Add(new Lacze(13, nodes[6], nodes[5], 1, 0)); //6-15

            //DOdanie wszystkich krawedzi do sieci
            network.krawedzie.AddRange(links);

            //Dodanie wszystkich wezlow do sieci
            network.wezly.AddRange(nodes);

            //zapuszczenie algorytmu floyda
            network.algorytmFloyda();

            //elementy sieci nie powinny byc zerowe
            Assert.IsFalse(network.Koszty.Length == 0);
            Assert.IsFalse(network.wezly.Count == 0);
            Assert.AreEqual(network.wezly.Count * network.wezly.Count, network.Koszty.Length);
            Assert.IsFalse(network.krawedzie.Count == 0);
            Assert.IsTrue(network.sprawdzSpojnosc());

            Sciezka path2_6 = new Sciezka(nodes[0], nodes[6]);

            path2_6.wyznaczSciezke(path2_6.Wezel1, path2_6.Wezel2, network.zwrocTabliceKierowaniaLaczami,
                                   network.zwrocTabliceKierowaniaWezlami, ref network.wezly, 1, network.Koszty, 1);

            path2_6.wyznaczWezly(path2_6.Wezel1);

            path2_6.pokazSciezke();

            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[0]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[1]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[2]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[5]));
            Assert.IsTrue(path2_6.WezlySciezki.Contains(nodes[6]));

            //Wyswietlenie tablic Floydowych
            //network.tabliceFloyd(network.zwrocTabliceKierowaniaLaczami, network.zwrocTabliceKierowaniaWezlami, network.Koszty);
        }
Beispiel #2
0
        public void testTables1()
        {
            Siec network = new Siec();

            List <Wezel>     nodes = new List <Wezel>();
            List <IPAddress> ips   = new List <IPAddress>();
            List <Lacze>     links = new List <Lacze>();

            ips.Add(IPAddress.Parse("127.0.0.1"));
            ips.Add(IPAddress.Parse("127.0.0.2"));
            ips.Add(IPAddress.Parse("127.0.0.3"));
            ips.Add(IPAddress.Parse("127.0.0.4"));
            ips.Add(IPAddress.Parse("127.0.0.5"));
            ips.Add(IPAddress.Parse("127.0.0.6"));
            ips.Add(IPAddress.Parse("127.0.0.7"));

            //Tworzenie wezlow o id odpowiadajacych adresom IP z listy
            for (int i = 0; i < ips.Count; i++)
            {
                nodes.Add(new Wezel(i + 1, ips[i].ToString()));
            }

            //Dodawanie krawedzi
            links.Add(new Lacze(0, nodes[0], nodes[3], 1));
            links.Add(new Lacze(1, nodes[3], nodes[6], 1));
            links.Add(new Lacze(2, nodes[6], nodes[2], 1));
            links.Add(new Lacze(3, nodes[2], nodes[1], 1));
            links.Add(new Lacze(4, nodes[3], nodes[4], 1));
            links.Add(new Lacze(5, nodes[4], nodes[5], 1));
            links.Add(new Lacze(6, nodes[5], nodes[3], 1));
            links.Add(new Lacze(7, nodes[3], nodes[0], 1));
            links.Add(new Lacze(8, nodes[1], nodes[3], 1));

            //DOdanie wszystkich krawedzi do sieci
            network.krawedzie.AddRange(links);

            //Dodanie wszystkich wezlow do sieci
            network.wezly.AddRange(nodes);

            //zapuszczenie algorytmu floyda
            network.algorytmFloyda();

            //elementy sieci nie powinny byc zerowe
            Assert.IsFalse(network.Koszty.Length == 0);
            Assert.IsFalse(network.wezly.Count == 0);
            Assert.AreEqual(network.wezly.Count * network.wezly.Count, network.Koszty.Length);
            Assert.IsFalse(network.krawedzie.Count == 0);
            Assert.IsTrue(network.sprawdzSpojnosc());

            /*
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 3].idWezla);
             * Assert.AreEqual(7, network.zwrocTabliceKierowaniaWezlami[3, 2].idWezla);
             * Assert.AreEqual(7, network.zwrocTabliceKierowaniaWezlami[3, 1].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 6].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 2].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 1].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 4].idWezla);
             * Assert.AreEqual(4, network.zwrocTabliceKierowaniaWezlami[0, 5].idWezla);
             * Assert.AreEqual(5, network.zwrocTabliceKierowaniaWezlami[3, 5].idWezla);
             * Assert.AreEqual(6, network.zwrocTabliceKierowaniaWezlami[4, 5].idWezla); */

            Sciezka path1_2 = new Sciezka(nodes[0], nodes[1]);

            path1_2.KrawedzieSciezki = path1_2.wyznaczSciezke(path1_2.Wezel1, path1_2.Wezel2, network.zwrocTabliceKierowaniaLaczami,
                                                              network.zwrocTabliceKierowaniaWezlami, ref network.wezly, 1, network.Koszty, 10);

            path1_2.wyznaczWezly(path1_2.Wezel1);

            path1_2.pokazSciezke();

            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[0]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[3]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[6]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[2]));
            Assert.IsTrue(path1_2.WezlySciezki.Contains(nodes[1]));

            //Wyswietlenie tablic Floydowych
            //network.tabliceFloyd(network.zwrocTabliceKierowaniaLaczami, network.zwrocTabliceKierowaniaWezlami, network.Koszty);
        }