Ejemplo n.º 1
0
        public void TestLoadAndRunDynamicSecondImpl()
        {
            var defaultSettings = Assembly.GetAssembly(typeof(IRoutes))
                                  .GetType("Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.Properties.Settings")
                                  .GetProperty("Default")
                                  .GetValue(null);

            defaultSettings.GetType().GetMethod("Reset").Invoke(defaultSettings, new object[] { });
            //defaultSettings.GetType().GetMethod("Reload").Invoke(defaultSettings, new object[] { });

            var cities = new Cities();

            cities.ReadCities(CitiesTestFile);

            IRoutes routes = RoutesFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.TestRoutesValidConstructor");

            Assert.AreEqual(42, routes.ReadRoutes("nonsense"));

            IRoutes routes2 = RoutesFactory.Create(cities);

            Assert.AreNotEqual(routes.GetType(), routes2.GetType());

            try
            {
                try
                {
                    defaultSettings.GetType().GetProperty("RouteAlgorithm").SetValue(defaultSettings, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.TestRoutesValidConstructor");
                }
                catch
                {
                    Assert.Fail("Make sure there is a String-property called \"RouteAlgorithm\" with User-scope.");
                }

                IRoutes routes3 = RoutesFactory.Create(cities);
                Assert.AreEqual(routes.GetType(), routes3.GetType());
            }
            finally
            {
                defaultSettings.GetType().GetMethod("Reset").Invoke(defaultSettings, new object[] { });
            }

            try
            {
                RoutesFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab5Test.TestRoutesInvalidConstructor");
                Assert.Fail("Should throw a NotSupportedException, because it doesn't have the right constructor");
            }
            catch (NotSupportedException)
            {
            }

            try
            {
                RoutesFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.Lab5Test.TestRoutesNoInterface");
                Assert.Fail("Should throw a NotSupportedException, because IRoutes is not implemented");
            }
            catch (NotSupportedException)
            {
            }
        }
Ejemplo n.º 2
0
        public void TestLoadDynamicInValid()
        {
            var cities = new Cities();
            // pass a name of a class that does not exist
            IRoutes routes = RoutesFactory.Create(cities, "Class.Does.Not.Exits");

            Assert.IsNull(routes);

            // pass a name of a class that exists, but does not implement the inetrface
            routes = RoutesFactory.Create(cities, "Cities");
            Assert.IsNull(routes);
        }
Ejemplo n.º 3
0
        public void TestLoadDynamicValid()
        {
            var cities = new Cities();
            // just test for correct dynamic creation of valid routed class from config
            IRoutes routes = RoutesFactory.Create(cities);

            Assert.IsInstanceOfType(routes, typeof(IRoutes));

            // now test for correct dynamic creation of valid routed class passed as string
            routes = RoutesFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.RoutesDijkstra");
            Assert.IsInstanceOfType(routes, typeof(IRoutes));
        }
Ejemplo n.º 4
0
        public void TestLoadAndRunDynamicClassicImpl()
        {
            var cities = new Cities();

            cities.ReadCities(CitiesTestFile);

            IRoutes routes = RoutesFactory.Create(cities);

            routes.ReadRoutes(LinksTestFile);

            Assert.AreEqual(28, cities.Count);

            // test available cities
            List <Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportMode.Rail);

            var expectedLinks = new List <Link>();

            expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2),
                                       new City("Aarau", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2),
                                       new City("Liestal", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2),
                                       new City("Basel", "Switzerland", 7000, 1, 2), 0));

            Assert.IsNotNull(links);
            Assert.AreEqual(expectedLinks.Count, links.Count);

            for (int i = 0; i < links.Count; i++)
            {
                Assert.IsTrue(
                    (expectedLinks[i].FromCity.Name == links[i].FromCity.Name &&
                     expectedLinks[i].ToCity.Name == links[i].ToCity.Name) ||
                    (expectedLinks[i].FromCity.Name == links[i].ToCity.Name &&
                     expectedLinks[i].ToCity.Name == links[i].FromCity.Name));
            }

            try
            {
                links = routes.FindShortestRouteBetween("doesNotExist", "either", TransportMode.Rail);
                Assert.Fail("Should throw a KeyNotFoundException");
            }
            catch (KeyNotFoundException)
            {
            }
        }
Ejemplo n.º 5
0
        public void TestLoadAndRunDynamic()
        {
            var cities = new Cities();

            cities.ReadCities(CitiesTestFile);

            IRoutes routes = RoutesFactory.Create(cities);

            routes.ReadRoutes(LinksTestFile);

            Assert.AreEqual(11, cities.Count);

            // test available cities
            List <Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail);

            var expectedLinks = new List <Link>();

            expectedLinks.Add(new Link(new City("Zürich", "Switzerland", 7000, 1, 2),
                                       new City("Aarau", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Aarau", "Switzerland", 7000, 1, 2),
                                       new City("Liestal", "Switzerland", 7000, 1, 2), 0));
            expectedLinks.Add(new Link(new City("Liestal", "Switzerland", 7000, 1, 2),
                                       new City("Basel", "Switzerland", 7000, 1, 2), 0));

            Assert.IsNotNull(links);
            Assert.AreEqual(expectedLinks.Count, links.Count);

            for (int i = 0; i < links.Count; i++)
            {
                Assert.AreEqual(expectedLinks[i].FromCity.Name, links[i].FromCity.Name);
                Assert.AreEqual(expectedLinks[i].ToCity.Name, links[i].ToCity.Name);
            }

            links = routes.FindShortestRouteBetween("doesNotExist", "either", TransportModes.Rail);
            Assert.IsNull(links);
        }
Ejemplo n.º 6
0
        public void TestLoadDynamicInvalid()
        {
            var cities = new Cities();

            // pass a name of a class that does not exist
            try
            {
                IRoutes routes = RoutesFactory.Create(cities, "Class.Does.Not.Exist");
                Assert.Fail("Should throw a NotSupportedException");
            }
            catch (NotSupportedException)
            {
            }

            // pass a name of a class that exists, but does not implement the interface
            try
            {
                IRoutes routes = RoutesFactory.Create(cities, "Cities");
                Assert.Fail("Should throw a NotSupportedException");
            }
            catch (NotSupportedException)
            {
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (Version " +
                              System.Reflection.Assembly.GetExecutingAssembly().GetName().Version +
                              ") ");
            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);

            Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude);
            Console.WriteLine(wayPoint.ToString());
            var bern     = new WayPoint("Bern", 46.949690, 7.442420);
            var tripolis = new WayPoint("Tripolis", 32.815062, 13.105445);

            Console.WriteLine(bern.Distance(tripolis));

            var cities = new Cities();

            cities.ReadCities("citiesTestDataLab4.txt");
            IRoutes routes = RoutesFactory.Create(cities);

            Console.WriteLine(routes);
            var count = routes.ReadRoutes("linksTestDataLab4.txt");

            //TestError Loading Lab9 b)
            var count2 = routes.ReadRoutes("linksTestDataLab42.txt");

            var c1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var c2 = new City("Bern", "Switzerland", 10, 1.1, 2.2);

            Console.WriteLine("\nsimpleObjectWriterTest");
            var stream = new StringWriter();
            var writer = new SimpleObjectWriter(stream);

            writer.Next(c1);
            Console.WriteLine(stream.ToString());

            Console.WriteLine("readTest Lab5");
            const string cityString1   = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Aarau\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n";
            const string cityString2   = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Bern\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n";
            const string cityString    = cityString1 + cityString2;
            var          expectedCity1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var          expectedCity2 = new City("Bern", "Switzerland", 10, 1.1, 2.2);
            var          stream2       = new StringReader(cityString);
            var          reader        = new SimpleObjectReader(stream2);
            var          city1         = reader.Next() as City;

            if (city1 == null)
            {
                Console.WriteLine("city was null");
            }
            Console.WriteLine(city1.ToString());

            Console.WriteLine("ActionTest Lab6");
            var actions = new Action[3];

            for (var i = 0; i < actions.Length; i++)
            {
                var z = i;
                actions[i] = () => Console.Write(z);
            }

            foreach (var a in actions)
            {
                a();
            }

            //Lab9 a1 c) Console & File Test of Readcities
            var cities3 = new Cities();

            cities3.ReadCities("citiesTestDataLab4.txt");
            IRoutes routes2 = RoutesFactory.Create(cities);

            //Lab9 a1 b) Loading from existing file
            var count3 = routes.ReadRoutes("linksTestDataLab4.txt");

            //Lab9 a1 b) Writing to file but not to console
            routesLogger.TraceEvent(TraceEventType.Information, 01, "this should not be on the console");


            //Lab9 a1 b) Loding not existing file
            var count4 = routes.ReadRoutes("linksTestDataLab42.txt");

            //Lab10 Tests
            Console.WriteLine("Lab10 Tests");
            Cities c10 = new Cities();

            c10.ReadCities(@"citiesTestDataLab10.txt");
            Console.WriteLine(c10.Count);

            Routes r10     = new RoutesFloydWarshall(cities);
            int    count10 = r10.ReadRoutes(@"linksTestDataLab10.txt");

            Console.WriteLine(count10);

            // test short routes in parallel mode
            r10.ExecuteParallel = true;
            sw.Start();
            List <Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail, null);

            sw.Stop();
            Console.WriteLine("Parallel: " + sw.ElapsedMilliseconds);

            // test short routes in seqential mode
            r10.ExecuteParallel = false;
            sw.Restart();
            List <Link> links2 = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail, null);

            sw.Stop();
            Console.WriteLine("Sequential: " + sw.ElapsedMilliseconds);
            //feststellung Parallel benötigt länger

            //Webpage of uploaded RoutePlannerLib
            //https://www.nuget.org/packages/FHNW-Lab11-Test/



            Console.ReadLine();
        }