static void Main(string[] args) { List <Parcel> totalParcelList = new List <Parcel>(); Console.WriteLine("Please enter size of package (cms) separated by commas : "); var userInput = Console.ReadLine(); Console.WriteLine("Would you like to opt in for speedy shipping? (y/n) : "); var speedyShippingInput = Console.ReadLine(); string[] parcelSizes = userInput.Split(","); ParcelCalculator calculator = new ParcelCalculator(); for (int i = 0; i < parcelSizes.Length; i++) { if (int.TryParse(parcelSizes[i], out int sizeOfPkg)) { totalParcelList.Add(calculator.CalculateCheapestCost(sizeOfPkg)); } else { Console.WriteLine($"Invalid output: {parcelSizes[i]}. This is excluded from the total cost."); } } PrintOutput(totalParcelList); if (speedyShippingInput.ToLower().Equals("y")) { PrintSpeedyShippingOutput(totalParcelList.CalculateDoubleParcelCost()); } }
public void WhenSizeIsAnInteger_ExpectSmallParcelSizeToBeReturned() { //Arrange ParcelCalculator calc = new ParcelCalculator(); int input = 0; //Act var result = calc.CalculateCheapestCost(input); //Assert Assert.IsTrue(result is Parcel); Assert.IsTrue(result.Name.Equals(AvailableParcelSizes.SmallParcel.Name)); Assert.IsTrue(result.Cost.Equals(AvailableParcelSizes.SmallParcel.Cost)); }
public void WhenSizeIsInMaxBoundarySizeLike49_ExpectMediumParcelToBeReturned() { //Arrange ParcelCalculator calc = new ParcelCalculator(); int input = 49; //Act var result = calc.CalculateCheapestCost(input); //Assert Assert.IsTrue(result is Parcel); Assert.IsTrue(result.Name.Equals(AvailableParcelSizes.MediumParcel.Name)); Assert.IsTrue(result.Cost.Equals(AvailableParcelSizes.MediumParcel.Cost)); }
[TestCase(255, 300, 150, 7.5)] //1 of the values exceeds the smaller size and is in medium public void IsPriceCalculatedCorrectly(int length, int breadth, int height, double exp) { //Arrange var model = new Parcel() { Length = length, Breadth = breadth, Height = height }; var sut = new ParcelCalculator(new ParcelTypeDictionary()); //Act var finalModel = sut.CalculatePrice(model); //Assert Assert.That(finalModel.Price, Is.EqualTo(exp)); }
public void ParcelIsNotRotated() { //Arrange var model = new Parcel() { Length = 300, Breadth = 400, Height = 200 }; var sut = new ParcelCalculator(new ParcelTypeDictionary()); //Act sut.RotateParcelIfNeeded(model); //Assert Assert.That(model.Height, Is.EqualTo(200)); Assert.That(model.Length, Is.EqualTo(300)); Assert.That(model.Breadth, Is.EqualTo(400)); }
public void IsParcelRotatedCorrectly(int initialLength, int initialBreadth, int initialHeight, int expectedLength, int expectedBreadth, int expectedHeight) { //Arrange var model = new Parcel() { Length = initialLength, Breadth = initialBreadth, Height = initialHeight }; var sut = new ParcelCalculator(new ParcelTypeDictionary()); //Act var finalModel = sut.RotateParcelIfNeeded(model); //Assert Assert.That(finalModel.Height, Is.EqualTo(expectedLength)); Assert.That(finalModel.Length, Is.EqualTo(expectedBreadth)); Assert.That(finalModel.Breadth, Is.EqualTo(expectedHeight)); }