Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                throw new ArgumentNullException("missing-argument");
            }

            var rep    = new infra.repository.RouteRepository($"stdin/{args[FileName]}");
            var routes = rep.Get();

            while (true)
            {
                Console.Write("please enter the route: ");
                var input       = Console.ReadLine();
                var routeToFind = input.Split('-');

                var origin      = routes.Find(q => q.AirportName == routeToFind[Origin]);
                var destination = routes.Find(q => q.AirportName == routeToFind[Destination]);

                if (origin != null && destination != null)
                {
                    var result = RouteService.BestRouteProcess(origin, destination);
                    Console.Write($"best route: {result.BestRouteDescription}");
                }
                else
                {
                    Console.Write($"invalid input route");
                }

                Console.WriteLine();
            }
        }
        public IActionResult GetBestRoute([FromRoute] string origin, string destination)
        {
            var routes = _repository.Get();

            var bestRoute = RouteService.BestRouteProcess(routes.Find(q => q.AirportName == origin), routes.Find(q => q.AirportName == destination));
            var result    = new RouteVM()
            {
                RoutePathDescription = bestRoute.RoutePathDescription, TotalCost = bestRoute.TotalCost
            };

            return(Ok(JsonSerializer.Serialize(result)));
        }
        public void process_valid_route_single_option()
        {
            var route1 = new Route("GRU");
            var route2 = new Route("CGD");

            route1.ConnectTo(route2, 10);

            var routes = new List <Route>();

            routes.Add(route1);
            routes.Add(route2);

            var result = RouteService.BestRouteProcess(route1, route2);

            Assert.True(result.RoutePathDescription.Equals("GRU-CGD"));
            Assert.True(result.TotalCost.Equals(10));
        }
        public void process_valid_route_multiple_options_one_connection()
        {
            var route1 = new Route("GRU");
            var route2 = new Route("BRC");
            var route3 = new Route("CGD");

            route1.ConnectTo(route2, 50);
            route1.ConnectTo(route3, 10);
            route3.ConnectTo(route2, 50);

            var routes = new List <Route>();

            routes.Add(route1);
            routes.Add(route2);
            routes.Add(route3);

            var result = RouteService.BestRouteProcess(route1, route2);

            Assert.True(result.RoutePathDescription.Equals("GRU-BRC"));
            Assert.True(result.TotalCost.Equals(50));
            Assert.True(result.Routes.Count == 2);
        }
        public void process_invalid_route()
        {
            var route1 = new Route("GRU");
            var route2 = new Route("BRC");

            route1.ConnectTo(route2, 10);

            var route3 = new Route("SCL");
            var route4 = new Route("ORL");

            route3.ConnectTo(route4, 20);

            var routes = new List <Route>();

            routes.Add(route1);
            routes.Add(route2);
            routes.Add(route3);
            routes.Add(route4);

            var result = RouteService.BestRouteProcess(route1, route4);

            Assert.True(result.RoutePathDescription.Equals("no route available"));
            Assert.True(result.Routes == null);
        }