public void FindSKUTest_VerifyByPrice() { StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value StockKeepingUnit wheel = new StockKeepingUnit("Wheel", 88.50); target.Add(wheel); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyre", 50.00)); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyrehorn", 11.50)); target.Add(wheel); string skuname = wheel.Name; // TODO: Initialize to an appropriate value //as we are not always returning the SAME instance, testing that would be pointless. StockKeepingUnit expected = new StockKeepingUnit(wheel); // TODO: Initialize to an appropriate value //we have enfourced a limit that the FindSKU will return null when there is 0 or > 1 SKU //in the list. StockKeepingUnit actual; actual = target.FindSKU(skuname); Assert.IsNotNull(actual, "There was no 'actual' item instance found"); Assert.AreEqual <double>(expected.Price, actual.Price, string.Format("L: {0} - R: {1}", expected.Price, actual.Price)); }
public void FindSKUTest_VerifyByName() { StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value StockKeepingUnit wheel = new StockKeepingUnit("Wheel", 88.50); target.Add(wheel); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyre", 50.00)); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyrehorn", 11.50)); target.Add(wheel); string skuname = wheel.Name; // TODO: Initialize to an appropriate value //as we are not always returning the SAME instance, testing that would be pointless. StockKeepingUnit expected = new StockKeepingUnit(wheel); // TODO: Initialize to an appropriate value StockKeepingUnit actual; actual = target.FindSKU(skuname); Assert.AreEqual <string>(expected.Name, actual.Name); }
/// <summary> /// /// </summary> public Receipt CalculateReceipt(string[] items) { Receipt result = new Receipt(); //zero the result StockKeepingUnits itemSKUs = new StockKeepingUnits(); foreach (var s in items) { StockKeepingUnit tempRef = fSKUs.FindSingletonSKU(s); if (tempRef != null) { itemSKUs.Add(new StockKeepingUnit(tempRef)); } else { result.AddRemark(String.Format("\"{0}\" was not recognised and skipped", s)); } } result.AddRemark(itemSKUs.ToString()); //now that we know what we are buting, we should apply the discounts result.Subtotal = itemSKUs.Price(); DiscountResults discountResults = fDiscounts.ApplyDiscounts(itemSKUs); result.Total = result.Subtotal - discountResults.Sum(); result.AddDiscount(discountResults.ToString()); return(result); }
/// <summary> /// /// </summary> public DiscountUnit(string discountName, StockKeepingUnit[] targeted, StockKeepingUnit[] discounted, double discount, int targetLevel) { Name = discountName; TargetItems = new StockKeepingUnits(targeted); DiscountedItems = new StockKeepingUnits(discounted); Discount = discount; TargetLevel = targetLevel; }
public void StockKeepingUnitsConstructorTest() { IEnumerable <StockKeepingUnit> collection = new List <StockKeepingUnit> { new StockKeepingUnit("A", 1.0), new StockKeepingUnit("B", 2.0), new StockKeepingUnit("C", 3.0) }; // TODO: Initialize to an appropriate value StockKeepingUnits target = new StockKeepingUnits(collection); Assert.IsNotNull(target); Assert.AreEqual <int>(target.Count, 3); }
public void ApplyDiscountTest2() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5); BuyItemsGetOneFreeDiscountUnit target = new BuyItemsGetOneFreeDiscountUnit("Test 1 discount", temp, 2); // TODO: Initialize to an appropriate value StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp, temp }); // TODO: Initialize to an appropriate value double expected = 1.5F; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); Assert.AreEqual <double>(expected, actual.Discount); }
public void ApplyDiscountTest() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5); BuyItemsLessPercentageDiscountUnit target = new BuyItemsLessPercentageDiscountUnit("Test 1 discount", temp, 1, 10.0); // TODO: Initialize to an appropriate value StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp }); // TODO: Initialize to an appropriate value double expected = 0.3F; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); Assert.IsTrue(System.Math.Round(expected, 2) == System.Math.Round(actual.Discount, 2)); }
public void ApplyDiscountTest() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5F); StockKeepingUnit temp2 = new StockKeepingUnit("Test2", 5.0F); BuyItemsGetPercentageFromItemDiscountUnit target = new BuyItemsGetPercentageFromItemDiscountUnit("Test 1 discount", temp, temp2, 2, 50.0); // TODO: Initialize to an appropriate value StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp, temp2 }); // TODO: Initialize to an appropriate value double expected = 2.5F; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); Assert.IsTrue(System.Math.Round(expected, 2) == System.Math.Round(actual.Discount, 2)); }
public void ApplyDiscountTest2() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5); BuyItemsLessPercentageDiscountUnit target = new BuyItemsLessPercentageDiscountUnit("Test 1 discount", temp, 2, 20.00F); // TODO: Initialize to an appropriate value StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp, temp }); // TODO: Initialize to an appropriate value double expected = 0.3; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); //Even though these were actually equal, precision screwed up the test.... *sigh* Assert.IsTrue(System.Math.Round(expected, 2) == System.Math.Round(actual.Discount, 2)); }
/// <summary> /// /// </summary> protected override bool CanApplyDiscount(StockKeepingUnits items) { //basically, we want to know that the list contains at least the target and discountItem //The contract we have is that this class will only ever have a single target sku type... so //the amount of items of the specific type to qualify is TargetLevel + 1 var sku = items.FindSKUs(TargetItems[0].Name); int discountItems = sku.Count; return(discountItems > 0); }
public void ApplyDiscountTest2() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5F); StockKeepingUnit temp2 = new StockKeepingUnit("Test2", 5.0F); BuyItemsGetPercentageFromItemDiscountUnit target = new BuyItemsGetPercentageFromItemDiscountUnit("Test 1 discount", temp, temp2, 2, 50.0); // TODO: Initialize to an appropriate value StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp, temp2, temp, temp, temp2, temp2 }); // TODO: Initialize to an appropriate value //there should be 2 discounts on Test 2 (50% or 5, so 2 x 2.5) and the extra Test2 should be ignored. double expected = 5.0F; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); Assert.IsTrue(System.Math.Round(expected, 2) == System.Math.Round(actual.Discount, 2), string.Format("L: {0} R: {1}", expected, actual.Discount)); }
/// <summary> /// /// </summary> protected override double CalculatedDiscount(StockKeepingUnits items) { //This is inefficient. I think I could have made this in to a more streamlines routine, but keeping the logic //in two chunks will simplify the code readibility. var sku = items.FindSKUs(TargetItems[0].Name); int count = sku.Count; int targetValue = (TargetLevel + 1); //this is how many items we need for each discount to apply int discountItems = ((count > TargetLevel) ? count / targetValue : 0); return(TargetItems[0].Price * discountItems); }
/// <summary> /// This finds the discounts to apply. /// </summary> /// <param name="items"></param> /// <returns></returns> public DiscountResults ApplyDiscounts(StockKeepingUnits items) { DiscountResults results = new DiscountResults(); foreach (var discount in this) { DiscountResult result = discount.ApplyDiscount(items); //we try to apply the discount results.Add(result); } return(results); }
public void ApplyDiscountTest3() { StockKeepingUnit temp = new StockKeepingUnit("Test1", 1.5); BuyItemsGetOneFreeDiscountUnit target = new BuyItemsGetOneFreeDiscountUnit("Test 1 discount", temp, 2); // TODO: Initialize to an appropriate value //this should match 2 offers, should ignore the extra item StockKeepingUnits items = new StockKeepingUnits(new StockKeepingUnit[] { temp, temp, temp, temp, temp, temp, temp }); // TODO: Initialize to an appropriate value double expected = 3.0F; // TODO: Initialize to an appropriate value DiscountResult actual = target.ApplyDiscount(items); Assert.AreEqual <double>(expected, actual.Discount); }
public void PriceTest() { StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value target.Add(new StockKeepingUnit("Wheel", 88.50)); target.Add(new StockKeepingUnit("Tyre", 50.00)); target.Add(new StockKeepingUnit("Tyrehorn", 11.50)); double expected = 150.00F; // TODO: Initialize to an appropriate value double actual; actual = target.Price(); Assert.AreEqual(expected, actual); }
/// <summary> /// Returns the discounted amount /// </summary> public virtual DiscountResult ApplyDiscount(StockKeepingUnits items) { double discount = 0.00; if (CanApplyDiscount(items)) { discount = CalculatedDiscount(items); return(new DiscountResult(Name, discount, true)); } else { return(new DiscountResult()); } }
/// <summary> /// /// </summary> protected override bool CanApplyDiscount(StockKeepingUnits items) { //basically, we want to know that the list contains at least the target and discountItem //The contract we have is that this class will only ever have a single target sku type... so //the amount of items of the specific type to qualify is TargetLevel + 1 var sku = items.FindSKUs(TargetItems[0].Name); int targetItems = sku.Count; //((targetItems > TargetLevel) ? targetItems / 2 : 0); sku = items.FindSKUs(DiscountedItems[0].Name); int discountItem = sku.Count; return(targetItems >= TargetLevel /* we have at least enough items to meet our quota*/ && discountItem > 0 /* we have at least one item to discount */); }
/// <summary> /// /// </summary> protected override bool CanApplyDiscount(StockKeepingUnits items) { //basically, we want to know that the list contains at least the target and discountItem //The contract we have is that this class will only ever have a single target sku type... so //the amount of items of the specific type to qualify is TargetLevel + 1 var sku = items.FindSKUs(TargetItems[0].Name); int count = sku.Count; //int discountItems = ((count > TargetLevel) ? count / TargetLevel : 0); int targetValue = (TargetLevel + 1); //this is how many items we need for each discount to apply int discountItems = ((count > TargetLevel) ? count / targetValue : 0); return(discountItems > 0); }
public void FindSKUsTest_VerifyWheelsCanBeFound() { StockKeepingUnits target = new StockKeepingUnits(); // TODO: Initialize to an appropriate value StockKeepingUnit wheel = new StockKeepingUnit("Wheel", 88.50); target.Add(wheel); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyre", 50.00)); target.Add(new StockKeepingUnit(wheel)); //because, we don't just use the same instance target.Add(new StockKeepingUnit("Tyrehorn", 11.50)); target.Add(wheel); string skuname = wheel.Name; // TODO: Initialize to an appropriate value StockKeepingUnits expected = new StockKeepingUnits(new StockKeepingUnit[] { new StockKeepingUnit(wheel), wheel, wheel, new StockKeepingUnit(wheel) }); // TODO: Initialize to an appropriate value StockKeepingUnits actual; actual = target.FindSKUs(skuname); Assert.AreEqual(expected.Count, actual.Count); }
/// <summary> /// /// </summary> protected override double CalculatedDiscount(StockKeepingUnits items) { //This is inefficient. I think I could have made this in to a more streamlines routine, but keeping the logic //in two chunks will simplify the code readibility. var sku = items.FindSKUs(TargetItems[0].Name); int targetItems = sku.Count; //((targetItems > TargetLevel) ? targetItems / 2 : 0); sku = items.FindSKUs(DiscountedItems[0].Name); int discountItem = sku.Count; //so, we need to know how many discounts we can apply int totalDiscountableItems = (targetItems > 0 ? targetItems / TargetLevel : 0); int numberOfActualDiscountItems = (totalDiscountableItems > discountItem ? discountItem : totalDiscountableItems); double actualPrice = (DiscountedItems[0].Price * numberOfActualDiscountItems); //what we should charge double actualDiscount = (actualPrice * (Discount / 100)); return(actualDiscount); }
/// <summary> /// /// </summary> protected override double CalculatedDiscount(StockKeepingUnits items) { //This is inefficient. I think I could have made this in to a more streamlines routine, but keeping the logic //in two chunks will simplify the code readibility. var sku = items.FindSKUs(TargetItems[0].Name); int discountItems = sku.Count; //we need to calculate how many items we need to qualify... if (TargetLevel == 1) { //discount applied for each item double actualPrice = (TargetItems[0].Price * discountItems); //what we should charge double actualDiscount = (actualPrice * (Discount / 100)); return(actualDiscount); } else { //we need more than one item to get the discount int qualifyingCount = (discountItems / (TargetLevel + 1)); double actualPrice = (TargetItems[0].Price * qualifyingCount); //what we should charge double actualDiscount = (actualPrice * (Discount / 100)); return(actualDiscount); } }
/// <summary> /// /// </summary> protected virtual double CalculatedDiscount(StockKeepingUnits items) { return(0.00); }
public void StockKeepingUnitsConstructorTest1() { StockKeepingUnits target = new StockKeepingUnits(); Assert.IsNotNull(target); }
/// <summary> /// /// </summary> protected virtual bool CanApplyDiscount(StockKeepingUnits items) { return(false); }