Exemplo n.º 1
0
        public void TestTask4FindRoutes()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);
            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));

            var routes = new RoutesDijkstra(cities);
            routes.ReadRoutes(LinksTestFile);

            Assert.AreEqual(11, cities.Count);

            // test available cities
            var links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail); 
            
            Assert.IsNotNull(links);
            Assert.AreEqual(expectedLinks.Count, links.Count);

            for (var 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);
        }
Exemplo n.º 2
0
        public async Task TestFindShortestRouteBetweenAsynch()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);
            routes.ReadRoutes(LinksTestFile);

            // do synchronous execution
            linksExpected = 
            routes.FindShortestRouteBetween("Basel", "Zürich", TransportModes.Rail);

            // do asynchronous execution
            linksActual =
             await routes.GoFindShortestRouteBetween("Basel", "Zürich", TransportModes.Rail);

            // not test the results
            Assert.IsNotNull(linksActual);
            Assert.AreEqual(linksExpected.Count, linksActual.Count);


            for (int i = 0; i < linksActual.Count; i++)
            {
                Assert.AreEqual(linksExpected[i].FromCity, linksActual[i].FromCity);
                Assert.AreEqual(linksExpected[i].ToCity, linksActual[i].ToCity);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to RoutePlanner (" + Assembly.GetExecutingAssembly().GetName().Version.ToString() + ")");
            Console.WriteLine();

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

            var wpBern = new WayPoint("Bern", 46.9479222, 7.4446085);
            var wpTripolis = new WayPoint("Tripolis", 32.8084124, 13.1509672);

            Console.WriteLine(wayPoint.ToString());

            Console.WriteLine(wpBern.ToString());
            Console.WriteLine(wpTripolis.ToString());

            Console.WriteLine("Distance: {0}" , wpBern.Distance(wpTripolis));

            var citiesLab2 = new Cities();
            citiesLab2.ReadCities("data\\citiesTestDataLab2.txt");

            var bern = new WayPoint("Bern", 46.95, 7.44);
            var tripolis = new WayPoint("Tripolis", 32.876174, 13.187507);
            double actual = bern.Distance(tripolis);
            
            Console.WriteLine();
            var findCity = citiesLab2.FindCity("Bern");

            if (findCity != null)
                Console.WriteLine("City {0} was found.", findCity.Name);
            else
                Console.WriteLine("City not found.");

            findCity = citiesLab2.FindCity("Dilli");

            if (findCity != null)
                Console.WriteLine("City {0} was found.", findCity.Name);
            else
                Console.WriteLine("City not found.");

            Console.WriteLine();
            Console.WriteLine("Test Routes");
            var citiesLab3 = new Cities();
            citiesLab3.ReadCities("data\\citiesTestDataLab3.txt");
            var reqWatcher = new RouteRequestWatcher();

            var routes = new RoutesDijkstra(citiesLab3);
            routes.RouteRequestEvent += reqWatcher.LogRouteRequests;
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Bus);
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Bus);

            routes.ReadRoutes("data\\linksTestDataLab3.txt");

            Console.WriteLine();
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void TestRoutesReadLinks()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);

            var count = routes.ReadRoutes(LinksTestFile);
            Assert.AreEqual(7, count);
        }
Exemplo n.º 5
0
        public void TestFindCitiesByTransportMode()
        {
            Cities cities = new Cities();
            cities.ReadCities(@"citiesTestDataLab3.txt");
            var routes = new RoutesDijkstra(cities);
            routes.ReadRoutes(@"linksTestDataLab3.txt");

            City[] citiesByMode = routes.FindCities(TransportModes.Rail);

            Assert.AreEqual(11, citiesByMode.Count());

            // there must be no cities
            City[] emptyCitiesByMode = routes.FindCities(TransportModes.Bus);
            Assert.AreEqual(0, emptyCitiesByMode.Count());

        }
Exemplo n.º 6
0
        public void TestTaskReadRoutes()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);
            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));

            var routes = new RoutesDijkstra(cities);
            var count = routes.ReadRoutes(LinksTestFile);

            Assert.AreEqual(10, count);
            Assert.AreEqual(10, routes.Count);

        }
Exemplo n.º 7
0
        public async Task TestFindShortestRouteBetweenAsynchProgress()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);
            routes.ReadRoutes(LinksTestFile);


            var progress = new Progress<string> (ProgressReport);
            // do asynchronous execution
            linksActual =
             await routes.GoFindShortestRouteBetween("Basel", "Zürich", TransportModes.Rail, progress);

            // the following assert has to be made after the routine routine returns 
            // assert, that in minimum 5 progress calls are made
            Assert.IsTrue(progCount >= 5, "less than 5 progress calls");

            // See comment in ProgressReport method
            Assert.IsFalse(doneMissing, String.Format("the progress message <{0}>does not contain <done>", failingMessage));
        }