public void FindNearestStation() { var point = new Point(51.499, -0.275); var tubeStations = new LinkedList<TubeStation>(); tubeStations.AddLast(new TubeStation("Acton Town", new Point(51.503071, -0.280303))); tubeStations.AddLast(new TubeStation("Chiswick Park", new Point(51.494371,-0.267737))); var finder = new SequentialTubeStationFinder(); var expectedNearestTubeStationName = "Acton Town"; var foundNearestTubeStation = finder.FindNearestTubeStation(tubeStations, point); Assert.AreEqual(expectedNearestTubeStationName, foundNearestTubeStation.Name); }
static void Main(string[] args) { if (args.Length == 2) { double latitude, longitude; if (Double.TryParse(args[0], out latitude) && Double.TryParse(args[1], out longitude)) { var currentLocation = new Point(latitude, longitude); try { using (var csvReader = new StreamReader(csvFileName)) { var tubeStationsFile = new TubeStationsFile(csvReader); var tubeStations = tubeStationsFile.TubeStations; var finder = new SequentialTubeStationFinder(); var nearestTubeStation = finder.FindNearestTubeStation(tubeStations, currentLocation); Console.WriteLine(String.Format("The nearest station is {0}.", nearestTubeStation.Name)); } } catch (Exception e) { Console.WriteLine("The CSV file could not be read:"); Console.WriteLine(e.Message); } } else { Console.WriteLine("The latitude and longitude need to be floating point numbers!"); } } else { Console.WriteLine("Give me the latitude and longitude of where you are!"); } }