Example #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);
        }
Example #2
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();
        }
Example #3
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);
            }
        }
Example #4
0
        public void TestTask2FiredEvents()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);

            // test available cities
            routes.RouteRequestEvent += TestForCorrectEventArgsWithFoundCities;
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);

            // test not existing cities
            routes.RouteRequestEvent -= TestForCorrectEventArgsWithFoundCities;
            routes.RouteRequestEvent += TestForCorrectEventArgsWithNotFoundCities;
            routes.FindShortestRouteBetween("doesNotExist", "either", TransportModes.Rail);
        }
Example #5
0
        public void TestTask2EventWithNoObserver()
        {
            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);

            // must run without exception
            routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail);
        }
Example #6
0
        public void TestRequestWatcher()
        {
            var reqWatch = new RouteRequestWatcher();

            var cities = new Cities();
            cities.ReadCities(CitiesTestFile);

            var routes = new RoutesDijkstra(cities);

            routes.RouteRequestEvent += reqWatch.LogRouteRequests;

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

            Assert.AreEqual(reqWatch.GetCityRequests("Zürich"), 2);
            Assert.AreEqual(reqWatch.GetCityRequests("Bern"), 1);
            Assert.AreEqual(reqWatch.GetCityRequests("Basel"), 0);
        }