public void CalculateStops()
        {
            string responseJson = "[{\"name\":\"Executor\",\"model\":\"Executor-class star dreadnought\",\"manufacturer\":\"Kuat Drive Yards, Fondor Shipyards\",\"cost_in_credits\":\"1143350000\",\"length\":\"19000\",\"max_atmosphering_speed\":\"n/a\",\"crew\":\"279144\",\"passengers\":\"38000\",\"cargo_capacity\":\"250000000\",\"consumables\":\"6 years\",\"hyperdrive_rating\":\"2.0\",\"MGLT\":\"40\",\"starship_class\":\"Star dreadnought\",\"pilots\":[],\"films\":[\"https://swapi.co/api/films/2/\",\"https://swapi.co/api/films/3/\"],\"created\":\"2014-12-15T12:31:42.547000Z\",\"edited\":\"2017-04-19T10:56:06.685592Z\",\"url\":\"https://swapi.co/api/starships/15/\"}]";
            var    ships        = JsonSerializer.Deserialize <Startship[]>(responseJson, SerializerOptions);
            var    results      = TripCalculator.CalculateTripStops(ships, 100000);

            Assert.NotNull(results);
        }
Esempio n. 2
0
        /// <summary>
        /// Prompts the user to input a valid distance
        /// </summary>
        public int PrintInputDistance()
        {
            int distance = 0;

            while (distance == 0)
            {
                Console.WriteLine("");
                Console.WriteLine("In order to calculate your trip, please provide the desired distance in MegaLights between 1 and 2147483647:");
                distance = TripCalculator.ParseDistance(Console.ReadLine());
            }

            return(distance);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Route | Start From Factory @ | Delivery Point | Delivery Time | PickUp Point | PickUp Time | Time In Truck");
            Console.WriteLine("==========================================================================================================");
            List <string> input = new List <string>();
            string        delivery;
            string        pickup;

            input = RouteFactory.Get("tsv");
            if (input.Validated("tsv"))
            {
                List <PickUpPoints>   pickUpPoints   = TripAdapter.getPickUpPoints(input);
                List <DeliveryPoints> deliveryPoints = TripAdapter.getDeliveryPoints(input);
                try
                {
                    IEnumerable <Routes> routes = TripCalculator.getRoutes(pickUpPoints, deliveryPoints).OrderBy(x => x.TimeInTruck).Take(1);


                    foreach (Routes s in routes)
                    {
                        if (s.DeliveryTime > 12)
                        {
                            delivery = Convert.ToString(s.DeliveryTime - 12) + " PM";
                        }
                        else
                        {
                            delivery = Convert.ToString(s.DeliveryTime) + " AM";
                        }
                        if (s.PickUpTime > 12)
                        {
                            pickup = Convert.ToString(s.PickUpTime - 12) + " PM";
                        }
                        else
                        {
                            pickup = Convert.ToString(s.PickUpTime) + " AM";
                        }
                        Console.WriteLine($"{s.Route} | {s.StartTime} | { s.DeliveryPoint} | {delivery} | {s.PickUpPoint} | {pickup} | {s.TimeInTruck} hour(s)");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            Console.ReadLine();
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of <see cref="FakeWebRequest"/>
        /// with the response to return.
        /// </summary>
        public async void Run()
        {
            //Instantiate the Api Wrapper for the desired Entity
            var helper = new WebHelper <Startship>(_logger);

            //Request all the Starships
            var ships = await helper.GetAll();

            //Print UI Welcome
            PrintWelcome();

            //ask User to input the distance
            var distance = PrintInputDistance();

            //do the math
            var stops = TripCalculator.CalculateTripStops(ships.ToArray(), distance);

            //Print the data in a formated table
            PrintStopsTable(stops);

            //print thank you and good bye
            PrintThankYouGoodBye();
        }
        public void ParseDistance()
        {
            var result = TripCalculator.ParseDistance("9999");

            Assert.Equal(9999, result);
        }