Esempio n. 1
0
        private IEnumerable <Stop> ParseStops(IEnumerable <string> lines)
        {
            var stopsDictionary = new Dictionary <string, List <Stop> >();

            foreach (var line in lines)
            {
                var fields     = line.Split(',');
                var name       = fields[0];
                var lat        = float.Parse(fields[1], CultureInfo.InvariantCulture);
                var lon        = float.Parse(fields[2], CultureInfo.InvariantCulture);
                var lineNumber = fields[4];
                var stop       = new Stop(name, lat, lon);
                if (!stopsDictionary.ContainsKey(name))
                {
                    stopsDictionary.Add(name, new List <Stop>());
                }

                var list      = stopsDictionary[name];
                var duplicate = list.FirstOrDefault(p => !AreDistinct(p, stop));
                var service   = new Service(lineNumber);
                if (duplicate == null)
                {
                    stop.AddService(service);
                    list.Add(stop);
                }
                else
                {
                    duplicate.AddService(service);
                }
            }

            return(stopsDictionary.Values.SelectMany(p => p).ToList());
        }
Esempio n. 2
0
        public void WhenMultipleStopsThenManyObjectives()
        {
            var stops = Enumerable.Range(0, 100).Select(i =>
            {
                var stop = new Stop("Stop" + i, 0.0f + i, 0.0f);
                stop.AddService(new Service("1"));
                return(stop);
            }).ToList();
            var service    = new ObjectiveGenerator(stops);
            var objectives = service.Generate(stops.First());

            Assert.Equal(10, objectives.Count());
        }
Esempio n. 3
0
        public void WhenNoConnectionBetweenStopsThenNoResults()
        {
            var startStop = new Stop("Start Stop", 10.0f, 20.0f);

            startStop.AddService(new Service("1"));
            var endStop = new Stop("End Stop", 15.0f, 20.0f);

            endStop.AddService(new Service("2"));
            var service    = new ObjectiveGenerator(new[] { startStop, endStop });
            var objectives = service.Generate(startStop);

            Assert.Empty(objectives);
        }
Esempio n. 4
0
        public void WhenTwoStopsThenOnlyObjectiveIsBetweenThem()
        {
            var startStop = new Stop("Start Stop", 10.0f, 20.0f);

            startStop.AddService(new Service("1"));
            var endStop = new Stop("End Stop", 15.0f, 20.0f);

            endStop.AddService(new Service("1"));
            var service    = new ObjectiveGenerator(new[] { startStop, endStop });
            var objectives = service.Generate(startStop);

            Assert.Collection(objectives, x => Assert.Equal(endStop, x.EndStop));
        }