Example #1
0
        public void Given_a_route_of_C_to_C_then_return_the_number_of_routes_with_a_distance_less_than_30()
        {
            var routingData = TestData.ConnectedStations;

            var routesFinder = new RouteFinder(routingData);

            var numberOfRoutes = routesFinder.GetRoutes("C", "C").WithADistanceLessThan(30).Count();

            Assert.That(numberOfRoutes, Is.EqualTo(7));
        }
Example #2
0
        public void Given_a_route_of_A_to_C_then_return_the_number_of_routes_with_exactly_4_stops()
        {
            var routingData = TestData.ConnectedStations;

            var routesFinder = new RouteFinder(routingData);

            var numberOfRoutes = routesFinder.GetRoutes("A", "C").WithExactStops(4).Count();

            Assert.That(numberOfRoutes, Is.EqualTo(3));
        }
Example #3
0
        public void Given_a_route_of_C_to_C_then_return_the_number_of_routes_with_no_more_than_3_stops()
        {
            var routingData = TestData.ConnectedStations;

            var routesFinder = new RouteFinder(routingData);

            var numberOfRoutes = routesFinder.GetRoutes("C", "C").WithMaxStops(3).Count();

            Assert.That(numberOfRoutes, Is.EqualTo(2));
        }
Example #4
0
        public void Should_try_a_similar_route_after_exhausting_one_path()
        {
            var routingData = new List <ConnectedStations>
            {
                new ConnectedStations("A", "C", 5),
                new ConnectedStations("C", "A", 4),
                new ConnectedStations("C", "E", 5),
                new ConnectedStations("E", "A", 3)
            };

            var routesFinder = new RouteFinder(routingData);

            var routes = routesFinder.GetRoutes("A", "A");

            Assert.True(routes.Any(r => OutputRouteAsString(r) == "ACCEEA"));
        }
Example #5
0
        public void Should_stop_searching_for_routes_after_10_stops()
        {
            var routingData = new List <ConnectedStations>
            {
                new ConnectedStations("A", "C", 5),
                new ConnectedStations("C", "A", 4)
            };

            var routesFinder = new RouteFinder(routingData);

            var routes = routesFinder.GetRoutes("A", "A");

            var maxStops = routes.OrderByDescending(r => r.Count()).First().Count();

            Assert.That(maxStops, Is.EqualTo(10));
        }
Example #6
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());
        }