public void TestLoadAndRunDynamic() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); IRoutes routes = RoutesFactory.Create(cities); routes.ReadRoutes(LinksTestFile); Assert.AreEqual(11, cities.Count); // test available cities List<Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail); 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)); Assert.IsNotNull(links); Assert.AreEqual(expectedLinks.Count, links.Count); for (int 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 TestTask1_FindRoutes() { Cities cities = new Cities(); cities.ReadCities(@"citiesTestDataLab4.txt"); List<Link> 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)); Routes routes = new RoutesFloydWarshall(cities); int count = routes.ReadRoutes(@"linksTestDataLab4.txt"); Assert.AreEqual(11, cities.Count); // test available cities routes.ExecuteParallel = true; List<Link> links = routes.FindShortestRouteBetween("Zürich", "Basel", TransportModes.Rail); Assert.IsNotNull(links); Assert.AreEqual(expectedLinks.Count, links.Count); for (int 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 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); } }
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(); }
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 TestLoadDynamicValid() { var cities = new Cities(); // just test for correct dynamic creation of valid routed class from config IRoutes routes = RoutesFactory.Create(cities); Assert.IsInstanceOfType(routes, typeof(IRoutes)); // now test for correct dynamic creation of valid routed class passed as string routes = RoutesFactory.Create(cities, "Fhnw.Ecnf.RoutePlanner.RoutePlannerLib_JW.RoutesDijkstra"); Assert.IsInstanceOfType(routes, typeof(IRoutes)); }
public void TestLoadDynamicInValid() { var cities = new Cities(); // pass a name of a class that does not exist IRoutes routes = RoutesFactory.Create(cities, "Class.Does.Not.Exits"); Assert.IsNull(routes); // pass a name of a class that exists, but does not implement the inetrface routes = RoutesFactory.Create(cities, "Cities"); Assert.IsNull(routes); }
public void TestDynamicWorld() { var cities = new Cities(); cities.ReadCities("citiesTestDataLab2.txt"); dynamic world = new World(cities); dynamic karachi = world.Karachi(); Assert.AreEqual("Karachi", karachi.Name); string notFound = world.Entenhausen(); Assert.AreEqual("The city \"Entenhausen\" does not exist!", notFound); }
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 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 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 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 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 void TestTask2_FindRoutes() { Cities cities = new Cities(); cities.ReadCities(@"citiesTestDataLab11.txt"); List<Link> expectedLinks = new List<Link>(); Routes routes = new RoutesFloydWarshall(cities); int count = routes.ReadRoutes(@"linksTestDataLab11.txt"); Assert.AreEqual(6372, cities.Count); // test available cities routes.ExecuteParallel = true; List<Link> links = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); routes.ExecuteParallel = false; List<Link> links2 = routes.FindShortestRouteBetween("Lyon", "Berlin", TransportModes.Rail); Assert.IsNotNull(links); Assert.AreEqual(13, links.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 RoutesFloydWarshall(Cities cities) : base(cities) { }
/// <summary> /// Default Creator /// </summary> /// <param name="cities"></param> /// <returns></returns> static public IRoutes Create(Cities cities) { return(Create(cities, Properties.Settings.Default.RouteAlgorithm)); }
//Kann abstract bleiben /// <summary> /// Initializes the Routes with the cities. /// </summary> /// <param name="cities"></param> public Routes(Cities cities) { this._cities = cities; }
public void TestFindNeighbours() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var loc = cities[0].Location; var neighbors = cities.FindNeighbours(loc, 2000); Assert.AreEqual(4, neighbors.Count); //verifies if the correct cities were found Assert.IsNotNull(neighbors.First(c=>c.Name == "Mumbai")); Assert.IsNotNull(neighbors.First(c => c.Name == "Karachi")); Assert.IsNotNull(neighbors.First(c => c.Name == "Dhaka")); Assert.IsNotNull(neighbors.First(c => c.Name == "Dilli")); }
public RoutesFloydWarshall(Cities cities) : base(cities) { }
public void TestFindNeighboursSorted() { var cities = new Cities(); cities.ReadCities(CitiesTestFile); var loc = cities[0].Location; var neighbors = cities.FindNeighbours(loc, 2000); Assert.AreEqual(4, neighbors.Count); //verify the correct order (sorted by distance) Assert.AreEqual("Mumbai", neighbors[0].Name); Assert.AreEqual("Karachi", neighbors[1].Name); Assert.IsTrue(loc.Distance(neighbors[0].Location) <= loc.Distance(neighbors[1].Location)); Assert.AreEqual("Dilli", neighbors[2].Name); Assert.IsTrue(loc.Distance(neighbors[1].Location) <= loc.Distance(neighbors[2].Location)); Assert.AreEqual("Dhaka", neighbors[3].Name); Assert.IsTrue(loc.Distance(neighbors[2].Location) <= loc.Distance(neighbors[3].Location)); }
public void TestTask5_CompareParallelSequential() { Cities cities = new Cities(); cities.ReadCities(@"citiesTestDataLab11.txt"); Assert.AreEqual(6372, cities.Count); Routes routes = new RoutesFloydWarshall(cities); routes.ExecuteParallel = true; long floydWarshallParallelTime = FindRoutes(routes); routes = new RoutesFloydWarshall(cities); routes.ExecuteParallel = false; long floydWarshallTime = FindRoutes(routes); // the sequentiel floydWarshal should be slower Assert.IsTrue(floydWarshallTime > floydWarshallParallelTime, "FloydWarshal parallel should be faster than sequential"); }
/// <summary> /// Default Creator /// </summary> /// <param name="cities"></param> /// <returns></returns> static public IRoutes Create(Cities cities) { return Create(cities, Properties.Settings.Default.RouteAlgorithm); }
public void TestReadCitiesAndIndexer() { const int readCitiesExpected = 10; var cities = new Cities(); Assert.AreEqual(readCitiesExpected, cities.ReadCities(CitiesTestFile)); Assert.AreEqual(readCitiesExpected, cities.Count); // read cities once again; cities should be added to the list Assert.AreEqual(readCitiesExpected, cities.ReadCities(CitiesTestFile)); // total count should be doubled Assert.AreEqual(2*readCitiesExpected, cities.Count); //verify first and last city Assert.AreEqual("Mumbai", cities[0].Name); Assert.AreEqual("Jakarta", cities[9].Name); // check for invalid index Assert.IsNull(cities[100]); }
public RoutesDijkstra(Cities cities) : base(cities) { }
public void TestTask3_CompareAlgorithms() { Cities cities = new Cities(); cities.ReadCities(@"citiesTestDataLab11.txt"); Assert.AreEqual(6372, cities.Count); Routes routes = new RoutesDijkstra(cities); long dijkstraTime = FindRoutes(routes); routes = new RoutesFloydWarshall(cities); routes.ExecuteParallel = false; long floydWarshallTime = FindRoutes(routes); // the sequentiel floydWarshal should be slower Assert.IsTrue(floydWarshallTime > dijkstraTime, "FloydWarshal should be slower"); }
public RoutesDijkstra(Cities cities) : base(cities) { }
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); }
/// <summary> /// Specific Creator with defined algorithm /// </summary> /// <param name="cities"></param> /// <param name="algorithmClassName"></param> /// <returns></returns> static public IRoutes Create(Cities cities, string algorithmClassName) { Assembly asm = Assembly.GetExecutingAssembly(); Type t = GetTypeFromAssembly(algorithmClassName, asm); return (t == null) ? null : Activator.CreateInstance(t, cities) as IRoutes; }
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); }
//Kann abstract bleiben /// <summary> /// Initializes the Routes with the cities. /// </summary> /// <param name="cities"></param> public Routes(Cities cities) { this._cities = cities; }