public static StopCalculationResult Build(StarshipResult starship, double distanceInMegaLights) { var result = new StopCalculationResult() { StarshipName = starship.Name }; double starshipMegaLights; double.TryParse(starship.MGLT, out starshipMegaLights); if (starshipMegaLights == 0 || starship.Consumables == "unknown") { result.TotalStops = 0; } else { var hours = distanceInMegaLights / starshipMegaLights; var consumables = starship.Consumables.ToHours(); var stops = consumables == 0 ? consumables : hours / consumables; result.TotalStops = Math.Floor(stops); } return(result); }
public void Builder_Should_Calculate_And_Create_Valid_Response() { // Arrange know result var megaLights = 1000000; var starship = new StarshipResult() { Name = "Millennium Falcon", MGLT = "75", Consumables = "2 months" }; var stopsExpected = 9; // Act var result = StopCalculationResultBuilder.Build(starship, megaLights); // Assert Assert.Equal(stopsExpected, result.TotalStops); }