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); }
public async Task TestFindShortestRouteBetweenAsync() { 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.FindShortestRouteBetweenAsync("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); } }
static void Main(string[] args) { Console.WriteLine("Welcome to RoutePlanner (Version {0})", Assembly.GetExecutingAssembly().GetName().Version); var bern = new WayPoint("Bern",46.951081, 7.438637); var tripolis = new WayPoint("Tripolis",32.883333333333, 13.166666666667); var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312); var City = new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312); Console.WriteLine(wayPoint); Console.WriteLine("Distance Bern to Tripolis: "+bern.Distance(tripolis)+"km"); Cities cities = new Cities(); cities.ReadCities(@"..\..\..\RoutePlannerTest\data\citiesTestDataLab2.txt"); RoutesDijkstra routes = new RoutesDijkstra(cities); routes.ReadRoutes(@"..\..\..\RoutePlannerTest\data\linksTestDataLab3.txt"); Cities citiesFail = new Cities(); citiesFail.ReadCities(@"irgendeinfile.txt"); Console.WriteLine("Starting parallel test......"); Cities citiesP = new Cities(); cities.ReadCities(@"..\..\..\RoutePlannerTest\data\citiesTestDataLab10.txt"); int warmUpRounds = 100; int measureRounds = 20; Routes routesP = new RoutesFloydWarshall(cities); int count = routesP.ReadRoutes(@"..\..\..\RoutePlannerTest\data\linksTestDataLab10.txt"); Console.WriteLine("doing warmup"); for (int i = 0; i < warmUpRounds; i++) { List<Link> links = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); } Stopwatch watch = new Stopwatch(); watch.Start(); Console.WriteLine("sequential mode: "); // test short routes in parallel mode routesP.ExecuteParallel = false; for (int i = 0; i < measureRounds; i++) { List<Link> links = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); } watch.Stop(); Console.WriteLine("Elapsed Time: " + watch.ElapsedMilliseconds + "ms"); watch.Reset(); watch.Start(); Console.WriteLine("parallel mode: "); // test short routes in parallel mode routesP.ExecuteParallel = true; for (int i = 0; i < measureRounds; i++) { List<Link> links2 = routesP.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); } watch.Stop(); Console.WriteLine("Elapsed Time: " + watch.ElapsedMilliseconds + "ms"); Console.WriteLine("Press any key to quit"); Console.ReadKey(); }
public void TestRoutesReadLinks() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new RoutesDijkstra(cities); var count = routes.ReadRoutes(LinksTestFile); Assert.AreEqual(7, count); }
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()); }
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); }
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)); }
public void TestRequestWatcher() { var reqWatch = new RouteRequestWatcher(); var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new RoutesDijkstra(cities); routes.ReadRoutes(LinksTestFile); 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(2, reqWatch.GetCityRequests("Zürich")); Assert.AreEqual(1, reqWatch.GetCityRequests("Bern")); Assert.AreEqual(0, reqWatch.GetCityRequests("Basel")); }
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); }