コード例 #1
0
        public Dictionary <string, string> GetAllResupplyStopsForSpaceTrip(SpaceTrip spaceTrip)
        {
            var starShips = GetAllStarships();

            ComputeSpacetripResupplyStops(spaceTrip, starShips);

            return(spaceTrip.ResupplyStops);
        }
コード例 #2
0
        public void SpaceTrip_GetResupplyStopsQuantityMaxDecimalDistance_Success()
        {
            // Arrange
            var           distance    = decimal.MaxValue.ToString();
            const decimal MGLT        = 10.00000000001M;
            const string  CONSUMABLES = "10 years";
            var           spaceTrip   = new SpaceTrip(distance);

            // Act
            var resupplyStops = spaceTrip.GetResupplyStopsQuantity(MGLT, CONSUMABLES);

            // Assert
            Assert.True(resupplyStops > 0);
        }
コード例 #3
0
        // Helper methods

        private static void ComputeSpacetripResupplyStops(SpaceTrip spaceTrip, IEnumerable <StarShip> starShips)
        {
            foreach (var starShip in starShips)
            {
                if (!IsMgltNumeric(starShip, out decimal speed))
                {
                    AddUnknownResultMessage(spaceTrip, starShip);
                    continue;
                }

                var numberOfStops = ComputeStops(starShip, spaceTrip);

                spaceTrip.AddResupplyStop(starShip.Name, numberOfStops);
            }
        }
コード例 #4
0
        public void SpaceTrip_GetResupplyStopsQuantity_MustReturn0()
        {
            // Arrange
            const string  DISTANCE        = "100";
            const decimal MGLT            = 10.00000000001M;
            const string  CONSUMABLES     = "10 hours";
            const int     EXPECTED_RESULT = 0;
            var           spaceTrip       = new SpaceTrip(DISTANCE);

            // Act
            var resupplyStops = spaceTrip.GetResupplyStopsQuantity(MGLT, CONSUMABLES);

            // Assert
            Assert.Equal(EXPECTED_RESULT, resupplyStops);
        }
コード例 #5
0
        private static string ComputeStops(StarShip starShip, SpaceTrip spaceTrip)
        {
            if (!decimal.TryParse(starShip.Mglt, out decimal mglt))
            {
                return("Not available (MGLT = 'unknown')");
            }
            var consumables = starShip.Consumables.ToLower();

            if (consumables == "unknown")
            {
                return("Not available (consumables = 'unknown')");
            }

            var result = spaceTrip.GetResupplyStopsQuantity(mglt, consumables);

            return(FormatResult(result));
        }
コード例 #6
0
 private static void AddUnknownResultMessage(SpaceTrip spaceTrip, StarShip starShip)
 {
     spaceTrip.AddResupplyStop(starShip.Name, "Not available (MGLT = 'Unknown')");
 }