public FindShortestRouteBetween ( string fromCity, string toCity, TransportModes mode, IProgress |
||
fromCity | string | |
toCity | string | |
mode | TransportModes | |
reportProgress | IProgress |
|
return | List |
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 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); }
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); } }
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); }
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); }
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); }