public void TestTask1FindCityInCities() { var expectedCity = "Zürich"; Cities cities = new Cities(); cities.ReadCities(CitiesTestFile); var notFound = cities.FindCity("noCity"); Assert.IsNull(notFound); var found = cities.FindCity(expectedCity); Assert.AreEqual(expectedCity, found.Name); // should work case insensitive found = cities.FindCity("züRicH"); Assert.AreEqual(expectedCity, found.Name); }
public void TestCorrectIndexingOfCities() { const int readCitiesExpected = 10; var cities = new Cities(); Assert.AreEqual(readCitiesExpected, cities.ReadCities(CitiesTestFile));;; City from = cities.FindCity("Mumbai"); City to = cities.FindCity("Istanbul"); List <City> foundCities = cities.FindCitiesBetween(from, to); // verify that Index property is initialized int i = 0; foreach (var city in foundCities) { Assert.AreEqual(i, city.Index); i++; } }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var city = _cities.FindCity(binder.Name); if (city == null) { result = string.Format("The city \"{0}\" does not exist!", binder.Name); } else { result = city; } return(true); }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var city = cities.FindCity(binder.Name); if (city == null) { result = "The city \"" + binder.Name + "\" does not exist!"; } else { result = city; } return(true); }
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { Console.WriteLine("Tryed to invoke: {0}", binder.Name); var city = _cities.FindCity(binder.Name); if (city != null) { result = city; } else { result = "The city \"" + binder.Name + "\" does not exist!"; } return(true); }
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); }
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(); }
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); //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 2a new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312); //Lab2 Aufgabe 2b Cities cities = new Cities(); Console.WriteLine("New cities: " + cities.ReadCities("citiesTestDataLab2.txt")); //Lab2 Aufgabe 2c /* * for (int i = 0; i < cities.Count;i++ ) * { * Console.WriteLine(cities[i].Name + ", " + cities[i].Country + ", " + cities[i].Population + ", " + cities[i].Location.Latitude + ", " + cities[i].Location.Longitude + ); + } */ //Lab2 Aufgabe 2d List <City> neighbours = cities.FindNeighbours(cities[1].Location, (double)17000.0); for (int i = 0; i < neighbours.Count; i++) { Console.WriteLine(neighbours[i].Name + ", " + neighbours[i].Country + ", " + neighbours[i].Population + ", " + neighbours[i].Location.Latitude + ", " + neighbours[i].Location.Longitude ); } //Lab3 Aufgabe 1 City city = cities.FindCity("shanghai"); Console.WriteLine("Name: " + city.Name + ", " + city.Country + ", " + city.Population + ", " + city.Location.Latitude + ", " + city.Location.Longitude ); //Lab3 Aufgabe 2c var reqWatch = new RouteRequestWatcher(); var routeCities = new Cities(); cities.ReadCities("citiesTestDataLab2.txt"); var routes = new RoutesDijkstra(routeCities); routes.RouteRequestEvent += reqWatch.LogRouteRequests; routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail); routes.FindShortestRouteBetween("Bern", "Zürich", TransportModes.Rail); routes.FindShortestRouteBetween("Basel", "Bern", TransportModes.Rail); const string cityString1 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Aarau\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n"; const string cityString2 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Bern\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n"; const string cityString = cityString1 + cityString2; var expectedCity1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2); var expectedCity2 = new City("Bern", "Switzerland", 10, 1.1, 2.2); var stream = new StringReader(cityString); var reader = new SimpleObjectReader(stream); var city1 = reader.Next() as City; var city2 = reader.Next() as City; routes.ReadRoutes("linksTestDataLab3.txt"); routes.ReadRoutes("linksTestDa.txt"); Console.ReadLine(); }