示例#1
0
        public void TestDeserializeSingleCity()
        {
            const string testdata =
                "Additional data - start\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\n"
                + "Country=\"Switzerland\"\r\n"
                + "Location is a nested object...\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\n"
                + "Latitude=1.1\r\n"
                + "Longitude=2.2\r\n"
                + "Name=\"Aarau\"\r\n"
                + "End of instance\r\n"
                + "Name=\"Aarau\"\r\n"
                + "Population=10\r\n"
                + "End of instance\r\n"
                + "Additional data - end\r\n";

            using (var sr = new StringReader(testdata))
            {
                Assert.AreEqual("Additional data - start", sr.ReadLine());
                var sor = new SimpleObjectReader(sr);
                sor.Next();

                Assert.AreEqual("Additional data - end", sr.ReadLine());
            }
        }
        public void TestDeserializeSingleCityWithValues()
        {
            var expectedCity = new City("Aarau", "Switzerland", 10, 1.1, 2.2);
            var stream       = new StringReader(CityWithValues);
            var reader       = new SimpleObjectReader(stream);
            var city         = reader.Next() as City;

            Assert.IsNotNull(city);
            Assert.AreEqual(expectedCity.Name, city.Name);
            Assert.AreEqual(expectedCity.Country, city.Country);
            Assert.AreEqual(expectedCity.Location.Latitude, city.Location.Latitude);
        }
示例#3
0
        public void TestSerializeOtherThings()
        {
            const string expected =
                "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.SerializeTest\r\n"
                + "ADouble=0.54444\r\n"
                + "BInt=1\r\n"
                + "CString=\"a\"\r\n"
                + "End of instance\r\n";
            var obj = new SimpleObjectReader(new StringReader(expected)).Next() as SerializeTest;

            Assert.IsNotNull(obj);
            Assert.AreEqual(obj.CString, "a");
            Assert.AreEqual(obj.ADouble, 0.54444);
            Assert.AreEqual(obj.BInt, 1);

            {
                var sw = new StringWriter();
                new SimpleObjectWriter(sw).Next(obj);
                Assert.AreEqual(expected, sw.ToString());
            }

            {
                var tl = new ThirdLevel()
                {
                    T = new SecondLevel()
                    {
                        T = obj
                    }
                };

                var sw = new StringWriter();
                new SimpleObjectWriter(sw).Next(tl);
                Assert.AreEqual(
                    "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.ThirdLevel\r\n"
                    + "T is a nested object...\r\n"
                    + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.SecondLevel\r\n"
                    + "T is a nested object...\r\n"
                    + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.SerializeTest\r\n"
                    + "ADouble=0.54444\r\n"
                    + "BInt=1\r\n"
                    + "CString=\"a\"\r\n"
                    + "End of instance\r\n"
                    + "End of instance\r\n"
                    + "End of instance\r\n", sw.ToString());
            }
        }
示例#4
0
        static string Lookup(string placeholder, SpecContext specCtx, Func <CalledMethodInfo, PrintContext> printCtx)
        {
            switch (placeholder)
            {
            case "$METHOD_CALLS$":
                return(specCtx.CalledMethods
                       .Aggregate(new StringBuilder(), (str, cmi) => {
                    str.AppendLine(printCtx(cmi).Print());
                    return str;
                }, sb => sb.ToString()));

            default:
                return(SimpleObjectReader.GetProperty(
                           placeholder.Trim('$').Split('.'),
                           specCtx));
            }
        }
示例#5
0
        public void TestDeserializeMultCitiesWithValues()
        {
            const string cityString1 =
                "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\n"
                + "Country=\"Switzerland\"\r\n"
                + "Location is a nested object...\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\n"
                + "Latitude=1.1\r\n"
                + "Longitude=2.2\r\n"
                + "Name=\"Aarau\"\r\n"
                + "End of instance\r\n"
                + "Name=\"Aarau\"\r\n"
                + "Population=10\r\n"
                + "End of instance\r\n";
            const string cityString2 =
                "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\n"
                + "Country=\"Switzerland\"\r\n"
                + "Location is a nested object...\r\n"
                + "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\n"
                + "Latitude=1.1\r\n"
                + "Longitude=2.2\r\n"
                + "Name=\"Bern\"\r\n"
                + "End of instance\r\n"
                + "Name=\"Bern\"\r\n"
                + "Population=10\r\n"
                + "End 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          reader        = new SimpleObjectReader(new StringReader(cityString));
            var          city1         = reader.Next() as City;

            Assert.IsNotNull(city1);
            Assert.AreEqual(expectedCity1.Name, city1.Name);
            Assert.AreEqual(expectedCity1.Country, city1.Country);
            Assert.AreEqual(expectedCity1.Location.Latitude, city1.Location.Latitude);
            var city2 = reader.Next() as City;

            Assert.IsNotNull(city2);
            Assert.AreEqual(expectedCity2.Name, city2.Name);
            Assert.AreEqual(expectedCity2.Country, city2.Country);
            Assert.AreEqual(expectedCity2.Location.Latitude, city2.Location.Latitude);
        }
示例#6
0
        //TODO: What does it test? Green with empty methods, class
        public void TestSerializationCulture()
        {
            const string expected =
                "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerTest.SerializeTest\r\n"
                + "ADouble=0.54444\r\n"
                + "BInt=1\r\n"
                + "CString=\"a\"\r\n"
                + "End of instance\r\n";

            var previousCulture = Thread.CurrentThread.CurrentCulture;

            try
            {
                // should work, even in "weird" cultures,
                // see http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
                Thread.CurrentThread.CurrentCulture = new CultureInfo("de-CH");
                var obj1 = new SimpleObjectReader(new StringReader(expected)).Next() as SerializeTest;
                var sw1  = new StringWriter();
                new SimpleObjectWriter(sw1).Next(obj1);

                Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
                var obj2 = new SimpleObjectReader(new StringReader(expected)).Next() as SerializeTest;
                var sw2  = new StringWriter();
                new SimpleObjectWriter(sw2).Next(obj2);

                Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
                var obj3 = new SimpleObjectReader(new StringReader(expected)).Next() as SerializeTest;
                var sw3  = new StringWriter();
                new SimpleObjectWriter(sw3).Next(obj3);

                Assert.AreEqual(sw1.ToString(), sw2.ToString());
                Assert.AreEqual(sw2.ToString(), sw3.ToString());
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = previousCulture;
            }
        }
        static void Main(string[] args)
        {
            Version version = Assembly.GetEntryAssembly().GetName().Version;

            Console.WriteLine("Welcome to RoutePlanner ({0})", version);


            WayPoint wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);

            Console.WriteLine(wayPoint.ToString());
            WayPoint wpBern     = new WayPoint("Bern", 46.9472221, 7.451202500000022);
            WayPoint wpTripolis = new WayPoint("Tripolis", 59.86062519999999, 17.650885199999948);

            Console.WriteLine("Distanz Bern-Tripolis: {0}km", wpBern.Distance(wpTripolis));

            City cBern = new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312);
            City c0    = new City("Mumbai", "India", 12383146, 18.96, 72.82);

            string serializedCity = string.Empty;

            using (StringWriter outstream = new StringWriter())
            {
                SimpleObjectWriter writer = new SimpleObjectWriter(outstream);
                writer.Next(cBern);
                serializedCity = outstream.ToString();
            }
            Console.WriteLine(serializedCity);

            using (StringReader inStream = new StringReader(serializedCity)) {
                SimpleObjectReader reader = new SimpleObjectReader(inStream);
                object             o      = reader.Next();
            }


            WayPoint wp = c0.Location;
            Cities   c  = new Cities();

            c.ReadCities("citiesTestDataLab2.txt");
            c.FindNeighbours(wp, 2000);
            c.ReadCities("citiesTestDataLab2.txt");

            var routes   = new RoutesDijkstra(c);
            var reqWatch = new RouteRequestWatcher();

            routes.RouteRequestEvent += reqWatch.LogRouteRequests;
            routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail);
            routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail);
            routes.FindShortestRouteBetween("India", "Mumbai", TransportModes.Rail);

            Console.WriteLine("City found: {0}", c.FindCity("Mumbai").Name);

            c.ReadCities("citiesTestDataLab4.txt");
            Routes r = new RoutesDijkstra(c);

            r.RouteRequestEvent += reqWatch.LogRouteRequests;
            r.ReadRoutes("linksTestDataLab4.txt");
            List <Link> l = r.FindShortestRouteBetween("Zürich", "Winterthur", TransportModes.Rail);

            foreach (Link link in l)
            {
                Console.WriteLine("from {0} to {1} in {2}", link.FromCity.Name, link.ToCity.Name, link.Distance);
            }
            Console.ReadKey();

            City          zurich     = c.FindCity("Zürich");
            City          winterthur = c.FindCity("Winterthur");
            ExcelExchange export     = new ExcelExchange();

            export.WriteToFile("Test.xls", zurich, winterthur, l);
        }
        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();
        }
        static void Main(string[] args)
        {
            //Lab1 Aufgabe 1
            Console.WriteLine("Welcome to RoutePlanner (Version " + Assembly.GetExecutingAssembly().GetName().Version + ")");

            //Lab1 Aufgabe 2d
            var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312);

            Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude);

            //Lab2 Aufgabe 1a
            Console.WriteLine(wayPoint);
            var wayPoint1 = new WayPoint("", 47.479319847061966, 8.212966918945312);
            var wayPoint2 = new WayPoint(null, 47.479319847061966, 8.212966918945312);

            Console.WriteLine(wayPoint1);
            Console.WriteLine(wayPoint2);

            //Lab2 Aufgabe 1b
            var bern     = new WayPoint("Bern", 46.948342, 7.442935);
            var tripolis = new WayPoint("Tripolis", 32.808858, 13.098922);

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

            //Lab2 Aufgabe 2a
            new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312);

            //Lab2 Aufgabe 2b
            Cities cities = new Cities();

            Console.WriteLine("New cities: " + cities.ReadCities("citiesTestDataLab2.txt"));

            //Lab2 Aufgabe 2c

            /*
             * for (int i = 0; i < cities.Count;i++ )
             * {
             *  Console.WriteLine(cities[i].Name + ", " + cities[i].Country
             + ", " + cities[i].Population
             + ", " + cities[i].Location.Latitude
             + ", " + cities[i].Location.Longitude
             +      );
             + }
             */

            //Lab2 Aufgabe 2d
            List <City> neighbours = cities.FindNeighbours(cities[1].Location, (double)17000.0);

            for (int i = 0; i < neighbours.Count; i++)
            {
                Console.WriteLine(neighbours[i].Name + ", " + neighbours[i].Country
                                  + ", " + neighbours[i].Population
                                  + ", " + neighbours[i].Location.Latitude
                                  + ", " + neighbours[i].Location.Longitude
                                  );
            }

            //Lab3 Aufgabe 1
            City city = cities.FindCity("shanghai");

            Console.WriteLine("Name: " + city.Name + ", " + city.Country
                              + ", " + city.Population
                              + ", " + city.Location.Latitude
                              + ", " + city.Location.Longitude
                              );


            //Lab3 Aufgabe 2c
            var reqWatch = new RouteRequestWatcher();

            var routeCities = new Cities();

            cities.ReadCities("citiesTestDataLab2.txt");

            var routes = new RoutesDijkstra(routeCities);

            routes.RouteRequestEvent += reqWatch.LogRouteRequests;

            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);
            routes.FindShortestRouteBetween("Basel", "Bern", TransportModes.Rail);


            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          stream        = new StringReader(cityString);
            var          reader        = new SimpleObjectReader(stream);
            var          city1         = reader.Next() as City;

            var city2 = reader.Next() as City;

            routes.ReadRoutes("linksTestDataLab3.txt");
            routes.ReadRoutes("linksTestDa.txt");

            Console.ReadLine();
        }