Пример #1
0
        public void should_get_different_routes_from_C_to_C()
        {
            var trainService = new NumberOfDiffRoutesService(GraphInput);

            var result = trainService.GetNumberDiffRoutes("C", "C", 30);

            Assert.AreEqual("The number of different routes from C to C with a distance of less than 30. In the sample data, the trips are: CDC, CEBC, CEBCDC, CDCEBC, CDEBC, CEBCEBCEBC, CEBCEBCEBC", result.Pregunta);
            Assert.AreEqual("7", result.Salida);
        }
Пример #2
0
        private static void RunOptionsAndReturnExitCode(Options opts)
        {
            var           graphInput = System.IO.File.ReadAllText(opts.InputFiles).ToUpper().Replace(" ", string.Empty);
            RouteResponse response   = new RouteResponse();

            switch (opts.Question.First())
            {
            case "d":
                var route = ((string[])opts.Question)[1].ToUpper().Replace(" ", string.Empty).Split(',').ToList();

                response = new DistanceRouteService(graphInput).GetRouteDistance(route);
                break;

            case "tmax":
                var trips    = ((string[])opts.Question)[1].ToUpper().Replace(" ", string.Empty).Split(',').ToList();
                var maxStops = Convert.ToInt16(((string[])opts.Question)[2].ToUpper().Replace(" ", string.Empty));

                response = new NumberOfTripsService(graphInput).GetMaxNumberOfTrips(trips[0], trips[1], maxStops);
                break;

            case "texact":
                trips = ((string[])opts.Question)[1].ToUpper().Replace(" ", string.Empty).Split(',').ToList();
                var exactStops = Convert.ToInt16(((string[])opts.Question)[2].ToUpper().Replace(" ", string.Empty));

                response = new NumberOfTripsService(graphInput).GetExactlyNumberOfTrips(trips[0], trips[1], exactStops);
                break;

            case "l":
                route = ((string[])opts.Question)[1].ToUpper().Replace(" ", string.Empty).Split(',').ToList();

                response = new ShortestRouteService(graphInput).GetShortestRoute(route[0], route[1]);
                break;

            case "r":
                route    = ((string[])opts.Question)[1].ToUpper().Replace(" ", string.Empty).Split(',').ToList();
                maxStops = Convert.ToInt16(((string[])opts.Question)[2].ToUpper().Replace(" ", string.Empty));

                response = new NumberOfDiffRoutesService(graphInput).GetNumberDiffRoutes(route[0], route[1], maxStops);
                break;
            }

            Console.WriteLine(string.Format("Pregunta: {0}; Salida: {1}",
                                            response.Pregunta, response.Salida));
        }