Exemplo n.º 1
0
        public void Given_a_route_of_B_to_B_then_return_the_shortest_distance_available_to_travel()
        {
            var routingData = TestData.ConnectedStations;

            var routesFinder = new RouteFinder(routingData);

            var distance = routesFinder.GetShortestRoute("B", "B").TotalDistance;

            Assert.That(distance, Is.EqualTo(9));
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            Action <object> cw = (obj) => Console.WriteLine(obj.ToString());

            cw("-----");

            IMatrix matrix = new StandardMatrix("AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7");

            // Calculate distances
            cw("#1 " + new Route("ABC", matrix));
            cw("#2 " + new Route("AD", matrix));
            cw("#3 " + new Route("ADC", matrix));
            cw("#4 " + new Route("AEBCD", matrix));
            cw("#5 " + new Route("AED", matrix));
            var finder = new RouteFinder(matrix);

            // Output 6 -> 2
            cw("---");
            var routes = finder.GetRoutesWithLessOrMaxStops("C", "C", 3);

            cw("#6 " + routes.Select(x => x.ToString()).Aggregate((current, next) => current + "\n#6 " + next));
            // Output 7 -> 3
            cw("---");
            routes = finder.GetRoutesWithMaxStops("A", "C", 4);
            cw("#7 " + routes.Select(x => x.ToString()).Aggregate((current, next) => current + "\n#7 " + next));
            cw("---");
            // Output 8,9 -> 9
            var route = finder.GetShortestRoute("A", "C");

            cw("#8 " + route);
            route = finder.GetShortestRoute("B", "B");
            cw("#9 " + route);

            // Output 10
            routes = finder.GetRoutes("C", "C", 30);
            cw("#10 Number of routes C to C with distance 30 " + routes.Count());
        }