public void ReadTubesFile()
        {
            var expectedTubeStations = new LinkedList<TubeStation>();
            expectedTubeStations.AddLast(new TubeStation("Acton Town",
                new Point(51.503071, -0.280303)));
            expectedTubeStations.AddLast(new TubeStation("Aldgate",
                new Point(51.514342, -0.075627)));
            expectedTubeStations.AddLast(new TubeStation("Aldgate East",
                new Point(51.51503, -0.073162)));
            expectedTubeStations.AddLast(new TubeStation("All Saints (DLR)",
                new Point(51.510477, -0.012625)));
            expectedTubeStations.AddLast(new TubeStation("Alperton",
                new Point(51.541209, -0.299516)));
            expectedTubeStations.AddLast(new TubeStation("Amersham",
                new Point(51.674129, -0.606514)));

            var csv = new StringBuilder()
                    .Append("\"Acton Town\",51.503071,-0.280303\n")
                    .Append("\"Aldgate\",51.514342,-0.075627\n")
                    .Append("\"Aldgate East\",51.51503,-0.073162\n")
                    .Append("\"All Saints (DLR)\",51.510477,-0.012625\n")
                    .Append("\"Alperton\",51.541209,-0.299516\n")
                    .Append("\"Amersham\",51.674129,-0.606514")
                    .ToString();

            var tubeStationsFile = new TubeStationsFile(new StringReader(csv));

            ICollection<TubeStation> actualTubeStations;
            actualTubeStations = tubeStationsFile.TubeStations;

            Assert.That(expectedTubeStations, Is.EqualTo(actualTubeStations));
        }
예제 #2
0
        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!");
            }
        }