public Dictionary <string, string> GetAllResupplyStopsForSpaceTrip(SpaceTrip spaceTrip) { var starShips = GetAllStarships(); ComputeSpacetripResupplyStops(spaceTrip, starShips); return(spaceTrip.ResupplyStops); }
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); }
// 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); } }
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); }
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)); }
private static void AddUnknownResultMessage(SpaceTrip spaceTrip, StarShip starShip) { spaceTrip.AddResupplyStop(starShip.Name, "Not available (MGLT = 'Unknown')"); }