public FindShortestRouteBetween ( string fromCity, string toCity, TransportModes mode ) : List | ||
fromCity | string | |
toCity | string | |
mode | TransportModes | |
return | List |
public async Task TestFindShortestRouteBetweenAsyncProgress() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new Routes(cities); routes.ReadRoutes(LinksTestFile); // do synchronous execution var linksExpected = routes.FindShortestRouteBetween("Basel", "Zürich", TransportMode.Rail); // do asynchronous execution var messages = new List<string>(); var progress = new Progress<string>(msg => messages.Add(msg)); var linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportMode.Rail, progress); // let pending tasks execute await Task.Yield(); // ensure that at least 5 progress calls are made Assert.IsTrue(messages.Distinct().Count()>=5, "Less than 5 distinct progress messages"); // ensure that all progress messages end with " done" Assert.IsTrue(messages.All(m => m.EndsWith(" done")), string.Format("Progress message \"{0}\" does not end with \" done\"", messages.FirstOrDefault(m => !m.EndsWith(" done")))); }
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); Console.WriteLine(wayPoint); //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 2b - FunktionsTest - Funktioniert Cities c = new Cities(); c.ReadCities("citiesTestDataLab2.txt"); Console.WriteLine("Test: {0}", c[5].Location.Latitude); var target = new WayPoint("Windisch", 0.564, 0.646); Console.WriteLine(target.ToString() + " vs. " + "WayPoint: Windisch 0.56/0.65"); //Lab3 Aufgabe 2 var reqWatch = new RouteRequestWatcher(); var routeCities = new Cities(); routeCities.ReadCities("citiesTestDataLab2.txt"); var routes = new Routes(routeCities); routes.RouteRequested += reqWatch.LogRouteRequests; routes.FindShortestRouteBetween("mumbai", "buenos aires", TransportMode.Rail); routes.FindShortestRouteBetween("dilli", "mumbai", TransportMode.Rail); routes.FindShortestRouteBetween("mumbai", "buenos aires", TransportMode.Rail); Console.ReadLine(); }
public void TestRequestWatcher() { var reqWatch = new RouteRequestWatcher(); var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new Routes(cities); routes.RouteRequested += reqWatch.LogRouteRequests; routes.FindShortestRouteBetween("Bern", "Zürich", TransportMode.Rail); routes.FindShortestRouteBetween("Bern", "Zürich", TransportMode.Rail); routes.FindShortestRouteBetween("Basel", "Bern", TransportMode.Rail); Assert.AreEqual(reqWatch.GetCityRequests(cities["Zürich"]), 2); Assert.AreEqual(reqWatch.GetCityRequests(cities["Bern"]), 1); Assert.AreEqual(reqWatch.GetCityRequests(cities["Basel"]), 0); Assert.AreEqual(reqWatch.GetCityRequests(cities["Lausanne"]), 0); }
public async Task TestFindShortestRouteBetweenAsync() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new Routes(cities); routes.ReadRoutes(LinksTestFile); // do synchronous execution var linksExpected = routes.FindShortestRouteBetween("Basel", "Zürich", TransportMode.Rail); // do asynchronous execution var linksActual = await routes.FindShortestRouteBetweenAsync("Basel", "Zürich", TransportMode.Rail); // now 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); } }
private long FindRoutes(Routes routes) { int count = routes.ReadRoutes(@"linksTestDataLab11.txt"); // test available cities Stopwatch timer = new Stopwatch(); timer.Start(); List<Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); return timer.ElapsedTicks; }
public void TestTask2FiredEvents() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new Routes(cities); // test available cities routes.RouteRequested += (sender, e) => { Assert.AreEqual("Bern", e.FromCity.Name); Assert.AreEqual("Zürich", e.ToCity.Name); }; routes.FindShortestRouteBetween("Bern", "Zürich", TransportMode.Rail); // test case insensitivity routes.FindShortestRouteBetween("BeRN", "ZüRiCh", TransportMode.Rail); // test not existing cities routes = new Routes(cities); routes.RouteRequested += (sender, e) => { Assert.Fail("Listeners should only be informed about valid requests."); }; try { routes.FindShortestRouteBetween("doesNotExist", "either", TransportMode.Rail); Assert.Fail("Should throw KeyNotFoundException when called with invalid city names."); } catch(KeyNotFoundException) { } }
public void TestTask2EventWithNoObserver() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var routes = new Routes(cities); // should run without exception routes.FindShortestRouteBetween("Bern", "Zürich", TransportMode.Rail); }