diff --git a/DOMAIN.md b/DOMAIN.md new file mode 100644 index 00000000..90c15485 --- /dev/null +++ b/DOMAIN.md @@ -0,0 +1,111 @@ + this is my domain + + + + + + +|Classes |Methods |Scenarios |output +|__________|_________________________________________|____________________________|______________________________ +|Customer |Customer(int funds) |Create a new customer with |-------- +| | |funds to spend | +| | | | +| | | | +| |ViewMenu() |Present a menu with |--------- +| | |bagels and | +| | |fillings. | +| | | | +| |EXTENTION 1: Showcost |Presents specials in menu | +| | | | +| |AddToBasket(string name, string variant |Manager accepts order |true +| | double remainingfunds) | | +| | | | +| | AddToBasket(string name, string variant | | +| |double remainingfunds,string filling) |Manager declines order. |false +| | | | +| | | | +| | | | +| | | | +| |RemoveItem(string name, string variant) |Removes item if it exists |true +| | |and manager updates capcaity| +| | | | +| | | Itemn does not exist |false +| | | | +| |ShowCost() |Calls basket to output cost |double +| | |of items in basket | +| | | | +| |EXTENSION 1: Showcost() |Discounts oppertunities |double +| | |discovered and applied | +| | | | +| |EXTENSION 2+3: Purchase() |Calls for a manager receipt.| true +| | |Basket is not empty | +| | | Then empties basket | +| | | | +| | |Calls for a manager receipt.| false +| | |Basket is empty | +| | | | +| | | | +|__________|_________________________________________|____________________________| +|Manager | | | +| | | | +| |ConfirmOrder(string namne, string variant| | +| |, double remainingFunds, int basketSize) | | +| | |Funds are sufficient for |true +| | |order, items is on the menu | +| | |and capcaity no full | +| | | | +| | |Funds are insufficient for |false +| | |order or item is not on menu| +| | |or capacity is full | +| | | | +| | | | +| |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true +| | | | +| | |NewCapacity is negative |false +| | | | +| | EXTENSION 2+3 | | +| | PrintReceipt(Basket basket) |Calls Receipt.PrintReceipt |------- +| | | | +| | | | +|__________|_________________________________________|____________________________| +|Basket | | | +| | ShowCost() |Shows sum of bagels in order|double +| | | | +| | Add(string name, string variant) |order added to basket |------ +| | | | +| | | | +| |Remove(string name, string variant) |Item exists in basket |true +| | | | +| | |Item does not exists in |false +| | |basket. | +|__________|_________________________________________|____________________________| +|Inventory | | | +| |IsInInventory(string name, string variant)|Item exists in inventory |true +| | | | +| | |Item does not exist in |false +| | |inventory | +| | | | +| |GetPrice(string name, string variant) |Item exists in inventory |double cost +| | | | +| | |Item does not exist in |-1 +| | |inventory | +|__________|_________________________________________|____________________________| +|Receipt |EXTENSION2+3 | | +| | | | +| |PrintReceipt(Basket) |Prints receipt of items in | string +| | |basket | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +|__________|_________________________________________|____________________________|______________________________________ + + + + +Extension 2 +As a customer, I'd like to recieve a receipt, so that I know I was charged correctly. \ No newline at end of file diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..c791cb43 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,264 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + + public Basket() + { + discounts.Add("BGLP", 0.0); + discounts.Add("BGLE", 0.0);// BaGeL Taste + discounts.Add("BGLS", 0.0);// BaGeL Taste + discounts.Add("BGLO", 0.0);// BaGeL Taste + discounts.Add("COFB", 0.0); + discounts.Add("COFW", 0.0); + discounts.Add("COFC", 0.0); + discounts.Add("COFL", 0.0); + } + public struct BasketItem + { + public string coffeeOrBagel = string.Empty; + public string filling = string.Empty; + + public BasketItem(string coffeeOrBagel) + { + this.coffeeOrBagel = coffeeOrBagel; + } + public BasketItem(string coffeeOrBagel, string filling) + { + this.coffeeOrBagel = coffeeOrBagel; + this.filling = filling; + } + } + + private double totalDiscount = 0.0; + public Dictionary discounts = new Dictionary(); + + Inventory inventory = new Inventory(); + public List basket = new List(); + public void Add(BasketItem item) + { + basket.Add(item); + } + + public int GetSize() + { + return basket.Count; + } + + public bool OrderInBasket(string name, string variant) + { + + foreach (var order in basket) + { + if(name == inventory.GetNameAndVariant(order.coffeeOrBagel).name && + variant == inventory.GetNameAndVariant(order.coffeeOrBagel).variant) + { + return true; + } + + } + return false; + } + + public double ShowCost() + { + totalDiscount = 0.0; + double retCost = 0.0; + int bagleAmountTaste = 0; + int bagleAmountPlain = 0; + + //these are for coffee discounts later + int cof1 = 0; + int cof2 = 0; + int cof3 = 0; + int cof4 = 0; + foreach(var item in discounts) + { + discounts[item.Key] = 0.0; //just a reset + } + + foreach (var item in basket) + { + if(item.coffeeOrBagel == "BGLP") //plain bagle + { + bagleAmountPlain++; + } + else if (item.coffeeOrBagel.Substring(0, 3) == "BGL") // flavorful bagel + { + bagleAmountTaste++; + } + if (item.coffeeOrBagel == "COFB") + { + cof1++; //cheapest + } + else if (item.coffeeOrBagel == "COFW") + { + cof2++; // middle + } + else if (item.coffeeOrBagel == "COFC" ) + { + cof3++;//expensive cof + } + else if (item.coffeeOrBagel == "COFL") + { + cof4++;//expensive cof + } + retCost += inventory.GetPrice(item.coffeeOrBagel); + retCost += inventory.GetPrice(item.filling); + } + //time to figure out bagel discount for flavorful + int spare12Taste = bagleAmountTaste % 12; + int discount12 = bagleAmountTaste / 12; // int should just remove the decimals + int spare6Taste = spare12Taste % 6; + int discount6 = spare12Taste / 6;// int should just remove the decimals + + discounts["BGLT"] = (double)discount12 * 1.89 + (double)discount6 * 0.45; + totalDiscount += (double)discount12 * 1.89 + (double)discount6 * 0.45; + retCost -= (double)discount12 * 1.89; + retCost -= (double)discount6 * 0.45; + + //time to figure out bagel discount for plain + int sparePlain = bagleAmountPlain % 12; + discount12 = bagleAmountPlain / 12; // int should just remove the decimals + discounts["BGLP"] = (double)discount12 * 0.69; + + totalDiscount += (double)discount12 * 0.69; + retCost -= (double)discount12 * 0.69; + //retCost -= (double)discount6 * 0.45; + // I will not implement a discount on 6 plain bagles as + // buying them induvidually costs 2.34 and the "discount" is 2.49 + // I will not be scamming my customers ;) + + //for coffe we will use the plain bagels first so the + //customer gets the cheaper bagel discounted. This is how + // most businisses do it + + for(int i = 0; i < cof1; i++) //black + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.13; + totalDiscount += 0.13; + discounts["COFB"] += 0.13; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.23; + totalDiscount += 0.23; + discounts["COFB"] += 0.23; + } + } + for (int i = 0; i < cof2; i++)//white/ + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.33; + totalDiscount += 0.33; + discounts["COFW"] += 0.33; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.43; + totalDiscount += 0.43; + discounts["COFW"] += 0.43; + } + } + for (int i = 0; i < cof3; i++)// capuccino + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.43; + totalDiscount += 0.43; + discounts["COFC"] += 0.43; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.53; + totalDiscount += 0.53; + discounts["COFC"] += 0.53; + } + } + for (int i = 0; i < cof4; i++)// latte + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.43; + totalDiscount += 0.43; + discounts["COFL"] += 0.43; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.53; + totalDiscount += 0.53; + discounts["COFL"] += 0.53; + } + } + discounts["BGLO"] = discounts["BGLT"]; + discounts["BGLE"] = discounts["BGLT"]; + discounts["BGLS"] = discounts["BGLT"]; + discounts["BGLT"] = 0.0; + + foreach (var item in discounts) + { + discounts[item.Key] = Math.Round(item.Value, 2); + } + + return Math.Round(retCost, 2); + } + + public double GetDiscount() + { + return Math.Round(this.totalDiscount, 2); + } + public bool RemoveFromBasket(string name, string variant) + { + string code = inventory.GetCode(name, variant); + if(name == "Coffee" || name == "Bagel") + { + for(int i = 0; i < basket.Count; i++) + { + if (basket[i].coffeeOrBagel == code) + { + basket.RemoveAt(i); + return true; + } + } + } + if (name == "Filling") + { + for (int i = 0; i < basket.Count; i++) + { + if (basket[i].filling == code) + { + BasketItem replaceItem = basket[i]; + replaceItem.filling = string.Empty; + return true; + } + } + } + return false; + } + + public void ClearBasket() + { + basket.Clear(); + } + + + } +} diff --git a/exercise.main/ClassDiagram1.cd b/exercise.main/ClassDiagram1.cd new file mode 100644 index 00000000..88982037 --- /dev/null +++ b/exercise.main/ClassDiagram1.cd @@ -0,0 +1,67 @@ + + + + + + + + Basket.cs + + + + + AAIAAACAAEAAiBCAAAAAAAAAAAAgAAACBAAAAAIAAAA= + Basket.cs + + + + + + + + + AAQEAACAAAAAABAAAAAAAAAEQAAAAAAGAgAAAAAAAAA= + Customer.cs + + + + + + + + + + + AAAACAAAAAAAAAAAAAYAAIAAAAAAAAACAAAAAAAAAAA= + Manager.cs + + + + + + + + + + + Inventory.cs + + + + + AAAAAAAAAAAAAAAAEAAAAAAAAAAAAIAAAAAAAASAAAE= + Inventory.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAIAAAAAAAAACAAAAAAAAAAA= + Receipt.cs + + + + + + + \ No newline at end of file diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs new file mode 100644 index 00000000..a1ed3b96 --- /dev/null +++ b/exercise.main/Customer.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Customer + { + Basket basket = new Basket(); + Inventory inventory = new Inventory(); + Manager manager = new Manager(); + double funds = 0; + public Customer(double funds) + { + this.funds = funds; + if(funds == 2222.0) + { + manager.ChangeCapcity(400); // this is for extension tests + } + } + + + public bool AddToBasket(string name, string variant) + { + if(manager.ConfirmOrder(name, variant, funds - basket.ShowCost(), basket.GetSize())) + { + //manager says yes + // funds OK! Capcity OK! Item exists OK! + Basket.BasketItem basketItem = new Basket.BasketItem(inventory.GetCode(name, variant)); + basket.Add(basketItem); + return true; + } + return false; + } + public bool AddToBasket(string name, string variant, string filling) + { + if (manager.ConfirmOrder(name, variant, funds - basket.ShowCost(), basket.GetSize())) + { + //manager says yes + // funds OK! Capcity OK! Item exists OK! + + //now we check filling + if (manager.ConfirmOrder("Filling", filling, funds - basket.ShowCost(), basket.GetSize()) && (name == "Bagel")) + { + Basket.BasketItem basketItem = new Basket.BasketItem(inventory.GetCode(name, variant), inventory.GetCode("Filling", filling)); + basket.Add(basketItem); + return true; + } + } + return false; + } + + + public bool Purchase() + { + bool result = manager.PrintReceipt(basket); + if (result) + { + basket.ClearBasket(); + return true; + } + return false; + } + + public bool RemoveItem(string name, string variant) + { + return basket.RemoveFromBasket(name, variant); + } + + public double ShowCost() + { + return basket.ShowCost(); + } + + public void ViewMenu() + { + Console.WriteLine("SKU\tName\tVariant\tPrice\tSpecial offers"); + foreach (var item in inventory.stock) + { + string printLine = item.Value.name + " " + item.Value.variant + + " " + item.Value.price; + if(item.Value.name == "Bagel") + { + printLine += " 6 for 2.49 / 12 for 3.99"; + } + else if (item.Value.name == "Coffee") + { + printLine += " Coffee & Bagel for 1.25"; + } + Console.WriteLine(printLine); + } + } + } +} diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs new file mode 100644 index 00000000..6cd0da2b --- /dev/null +++ b/exercise.main/Inventory.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Inventory + { + public struct Product + { + public double price; + public string name; + public string variant; + + public Product(double price, string name, string variant) + { + this.price = price; + this.name = name; + this.variant = variant; + } + } + public Dictionary stock = new Dictionary(); + + + public Inventory() + { + Product product = new Product(0.49, "Bagel", "Onion"); + stock.Add("BGLO", product); + product = new Product(0.39, "Bagel", "Plain"); + stock.Add("BGLP", product); + product = new Product(0.49, "Bagel", "Everything"); + stock.Add("BGLE", product); + product = new Product(0.49, "Bagel", "Sesame"); + stock.Add("BGLS", product); + product = new Product(0.99, "Coffee", "Black"); + stock.Add("COFB", product); + product = new Product(1.19, "Coffee", "White"); + stock.Add("COFW", product); + product = new Product(1.29, "Coffee", "Capuccino"); + stock.Add("COFC", product); + product = new Product(1.29, "Coffee", "Latte"); + stock.Add("COFL", product); + product = new Product(0.12, "Filling", "Bacon"); + stock.Add("FILB", product); + product = new Product(0.12, "Filling", "Egg"); + stock.Add("FILE", product); + product = new Product(0.12, "Filling", "Cheese"); + stock.Add("FILC", product); + product = new Product(0.12, "Filling", "Cream Cheese"); + stock.Add("FILX", product); + product = new Product(0.12, "Filling", "Smoked Salmon"); + stock.Add("FILS", product); + product = new Product(0.12, "Filling", "Ham"); + stock.Add("FILH", product); + } + + public bool IsInInventory(string name, string variant) + { + foreach (var product in stock) + { + if(product.Value.name == name && product.Value.variant == variant) + { + return true; + } + } + return false; + } + + public double GetPrice(string name, string variant) + { + foreach (var product in stock) + { + if (product.Value.name == name && product.Value.variant == variant) + { + return product.Value.price; + } + } + return -1; + } + + public double GetPrice(string sku) + { + foreach (var product in stock) + { + if (product.Key == sku) + { + return product.Value.price; + } + } + return 0; + } + + public string GetCode(string name, string variant) + { + foreach (var product in stock) + { + if (product.Value.name == name && product.Value.variant == variant) + { + return product.Key; + } + } + return string.Empty; + } + + public Product GetNameAndVariant(string sku) + { + return stock[sku]; + } + } +} diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs new file mode 100644 index 00000000..200acb35 --- /dev/null +++ b/exercise.main/Manager.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Manager + { + private int capacity = 5; + Inventory inventory = new Inventory(); + + public bool ChangeCapcity(int newCapacity) + { + if(newCapacity < 0) + { + return false; + } + capacity = newCapacity; + return true; + + } + + public bool ConfirmOrder(string name, string variant, double remainingFunds, int basketSize) + { + if(!inventory.IsInInventory(name, variant)) + { + return false; // item does not exist on menu + } + if(inventory.GetPrice(name, variant) > remainingFunds) + { + return false; //insufficient funds + } + if(basketSize >= capacity && name != "Filling") + { + return false; // basket cannot exceed capacity + // note that fillings do not take up space, they are included in the bagel + } + + return true; + } + + public bool PrintReceipt(Basket basket) + { + if(basket.GetSize() > 0) // if basket is not empty + { + Receipt receipt = new Receipt(); + receipt.PrintReceipt(basket); + return true; + } + return false; + } + } +} diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..a88bc21a 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,7 @@ // See https://aka.ms/new-console-template for more information +using exercise.main; +using System.Text; + Console.WriteLine("Hello, World!"); +//Customer cus = new Customer(22); +//cus.ViewMenu(); diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs new file mode 100644 index 00000000..63eae617 --- /dev/null +++ b/exercise.main/Receipt.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Receipt + { + Inventory inventory; + public Receipt() + { + inventory = new Inventory(); + } + + public void PrintReceipt(Basket basket) + { + //this info is always on a receipt + StringBuilder receipt = new StringBuilder(); + receipt.AppendLine("\n ~~~ Bob's Bagels ~~~"); + receipt.AppendLine($"\n {DateTime.Now}"); + receipt.AppendLine("\n----------------------------\n"); + + //here we look through the basket + // string is the product sku, int is the amount of times it occurs + Dictionary order = new Dictionary(); + + foreach(var item in basket.basket) + { + if(!order.ContainsKey(item.coffeeOrBagel)) + { + order.Add(item.coffeeOrBagel, 1); //adds first + } + else + { + order[item.coffeeOrBagel]++; //adds another + } + if (!order.ContainsKey(item.filling) && item.filling != string.Empty) + { + order.Add(item.filling, 1); //adds first + } + else if(item.filling != string.Empty) + { + order[item.filling]++; //adds another + } + } + foreach(var item in order) + { + double cost = inventory.GetPrice(item.Key); + string realProductName = $"{inventory.GetNameAndVariant(item.Key).variant} {inventory.GetNameAndVariant(item.Key).name}"; + receipt.Append($"{realProductName}"); + for(int i = 0; i < 19 - realProductName.Length; i++) + { + receipt.Append(" "); + } + receipt.Append($"{item.Value}"); + for (int i = 0; i < 4 - item.Value.ToString().Length; i++) + { + receipt.Append(" "); + } + receipt.AppendLine($"£{Math.Round(cost * item.Value, 2)}"); + + //here discounts are printed for each item. + if(basket.discounts.ContainsKey(item.Key) && + Math.Round(basket.discounts[item.Key], 2) > 0.0) + { + //item is here and discount exists + for(int i = 0; i < 25 - Math.Round(basket.discounts[item.Key], 2).ToString().Length; i++) + { + receipt.Append(" "); + } + receipt.AppendLine($"(-£{Math.Round(basket.discounts[item.Key], 2)})"); + + //because of how discounts are applied, some need to be 0'd out + if(item.Key == "BGLO" || item.Key == "BGLE" || item.Key == "BGLS") + { + basket.discounts["BGLO"] = 0.0; + basket.discounts["BGLS"] = 0.0; + basket.discounts["BGLE"] = 0.0; + } + } + } + + receipt.AppendLine($"\n----------------------------"); + receipt.Append($"Total"); + + double costTotal = basket.ShowCost(); + //turns out it already applies discouts so extension 2+3 at the same time it is + for (int i = 0; i < 23 - costTotal.ToString().Length; i++) + { + receipt.Append(" "); + } + receipt.AppendLine($"£{costTotal}\n"); + receipt.AppendLine($"You saved a total of £{basket.GetDiscount()}\n on this shop"); + receipt.AppendLine("\n Thank you\n for your order!"); + + + Console.WriteLine(receipt.ToString()); + } + } +} diff --git a/exercise.sln b/exercise.sln index 0efb5453..ceea7fef 100644 --- a/exercise.sln +++ b/exercise.sln @@ -9,6 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "exercise.tests", "exercise. EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{825CCFE7-4F2E-4770-8393-FEB732F66EE4}" ProjectSection(SolutionItems) = preProject + DOMAIN.md = DOMAIN.md extension1.md = extension1.md extension2.md = extension2.md extension3.md = extension3.md @@ -34,4 +35,7 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A68A95BD-C6FC-4E76-B4F1-E388DD393684} + EndGlobalSection EndGlobal diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs new file mode 100644 index 00000000..d2a5621d --- /dev/null +++ b/exercise.tests/BasketTest.cs @@ -0,0 +1,50 @@ +using exercise.main; +using static exercise.main.Basket; +namespace BasketTest.tests; + +public class BasketTests +{ + [TestCase("Bagel", "Everything")] + [TestCase("Coffee", "White")] + [TestCase("Bagel", "Sesame")] + [TestCase("Bagel", "Plain")] + [TestCase("Coffee", "Latte")] + public void TestAdd(string name, string variant) + { + Basket basket = new Basket(); + + Inventory inventory = new Inventory(); + BasketItem item = new BasketItem(inventory.GetCode(name, variant)); + basket.Add(item); + + bool inBasket = basket.OrderInBasket(name, variant); + + Assert.IsTrue(inBasket); + } + + + [TestCase("Bagel", "Everything", 0.49)] + [TestCase("Bagel", "Plain", 0.39)] + [TestCase("Coffee", "Latte", 0.86)] //cost because discount + public void TestShowCost(string name, string variant, double cost) + { + Basket basket = new Basket(); + Inventory inventory = new Inventory(); + BasketItem item = new BasketItem(inventory.GetCode("Bagel", "Onion")); + basket.Add(item); + item = new BasketItem(inventory.GetCode("Bagel", "Plain")); + basket.Add(item); + item = new BasketItem(inventory.GetCode(name, variant)); + basket.Add(item); + + double expectedCost = 0.88 + cost; + + + double result = basket.ShowCost(); + + Assert.That(result == expectedCost); + } + + + +} diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs new file mode 100644 index 00000000..e3481ed0 --- /dev/null +++ b/exercise.tests/CustomerTest.cs @@ -0,0 +1,99 @@ +using exercise.main; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + public class CustomerTest + { + + [TestCase("Bagel", "Plain", 2.0, new bool[] {true, true})] + [TestCase("Fish", "Plain", 2.0, new bool[] { false, false })] + [TestCase("Bagel", "Kangeroo", 2.0, new bool[] { false, false })] + [TestCase("Bagel", "Plain", 0.6, new bool[] { true, false })] + [TestCase("Bagel", "Plain", 222.0, new bool[] { true, true, true, true, true, false, false })] + [TestCase("Coffee", "White", 2.0, new bool[] { true, false })] + public void TestAddToBasket(string name, string variant, double funds,bool[] expected) + { + Customer customer = new Customer(funds); + + for(int i = 0; i < expected.Length; i++) + { + customer.ShowCost(); + bool result = customer.AddToBasket(name, variant); + Assert.That(result == expected[i]); + } + } + + + + [TestCase("Bagel", "Plain", 2.0, "Bacon", new bool[] { true, true })] + [TestCase("Fish", "Plain", 2.0, "Bacon", new bool[] { false, false })] + [TestCase("Bagel", "Kangeroo", 2.0, "Bacon", new bool[] { false, false })] + [TestCase("Bagel", "Plain", 0.7, "Egg", new bool[] { true, false })] + [TestCase("Bagel", "Plain", 222.0, "Cheese", new bool[] { true, true, true, true, true, false, false })] + [TestCase("Coffee", "White", 2.0, "Bacon", new bool[] { false, false })] + public void TestAddToBasketWithFilling(string name, string variant, double funds, string filling, bool[] expected) + { + Customer customer = new Customer(funds); + + for (int i = 0; i < expected.Length; i++) + { + customer.ShowCost(); + bool result = customer.AddToBasket(name, variant, filling); + Assert.That(result == expected[i]); + } + } + + + [TestCase("Bagel", "Plain", 222.0, 2, 2.5)] + [TestCase("Fish", "Plain", 222.0, 4, 2.28)]//does not exist + [TestCase("Bagel", "Kangeroo", 222.0, 2, 2.28)] //does not exist + [TestCase("Bagel", "Everything", 0.6, 4, 0.49)] //fund issue + [TestCase("Bagel", "Everything", 2222.0, 28, 11.46)] + [TestCase("Bagel", "Plain", 2222.0, 19, 8.44)] + [TestCase("Coffee", "White", 222.0, 1, 3.47)] + public void TestShowCost(string name, string variant, double funds, int iterations, double expectedCost) + { + Customer customer = new Customer(funds); + + + + for (int i = 0; i < iterations; i++) + { + customer.AddToBasket(name, variant); + } + + // FOR EXTENSION TESTS + //_____________________________________ + customer.AddToBasket("Coffee", "Black"); + customer.AddToBasket("Coffee", "Latte"); + //________________________________ + + double cost = customer.ShowCost(); + Assert.That(cost == expectedCost); + } + + + [TestCase("Bagel", "Plain", true)] + [TestCase("Fish", "Plain", false)] + [TestCase("Bagel", "Kangeroo", false)] + [TestCase("Bagel", "Plain", true)] + [TestCase("Bagel", "Plain", true)] + [TestCase("Coffee", "White", true)] + public void TestRemoveFromBasket(string name, string variant, bool expected) + { + Customer customer = new Customer(222.0); + customer.AddToBasket(name, variant); + + bool result = customer.RemoveItem(name, variant); + + Assert.That(result == expected); + } + + + } +} diff --git a/exercise.tests/InventoryTest.cs b/exercise.tests/InventoryTest.cs new file mode 100644 index 00000000..9a4b03bc --- /dev/null +++ b/exercise.tests/InventoryTest.cs @@ -0,0 +1,48 @@ +using exercise.main; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + + public class InventoryTest + { + + [TestCase("BOGUS", "fake", false)] + [TestCase("Bagel", "Everything", true)] + [TestCase("Coffee", "Rainbow", false)] + [TestCase("Filling", "Bacon", true)] + [TestCase("Filling", "Smoked Salmon", true)] + [TestCase("Bagel", "Plain", true)] + [TestCase("A lie", "Ham", false)] + [TestCase("Coffee", "Latte", true)] + public void TestIsInInventory(string name, string variant, bool expected) + { + Inventory inventory = new Inventory(); + + bool result = inventory.IsInInventory(name, variant); + + Assert.That(result == expected); + } + + [TestCase("BOGUS", "fake", -1)] + [TestCase("Bagel", "Everything", 0.49)] + [TestCase("Coffee", "Rainbow", -1)] + [TestCase("Filling", "Bacon", 0.12)] + [TestCase("Filling", "Smoked Salmon", 0.12)] + [TestCase("Bagel", "Plain", 0.39)] + [TestCase("A lie", "Ham", -1)] + [TestCase("Coffee", "Latte", 1.29)] + public void TestGetPrice(string name, string variant, double expected) + { + Inventory inventory = new Inventory(); + double result = inventory.GetPrice(name, variant); + + Assert.That(result == expected); + } + + } +} diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs new file mode 100644 index 00000000..a91828f6 --- /dev/null +++ b/exercise.tests/ManagerTest.cs @@ -0,0 +1,55 @@ +using exercise.main; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + public class ManagerTest + { + + [TestCase(2)] + [TestCase(-2)] + [TestCase(1)] + [TestCase(0)] + [TestCase(27)] + [TestCase(38)] + [TestCase(8)] + [TestCase(-444)] + public void TestChangeCapacity(int newCapacity) + { + Manager manager = new Manager(); + bool expected = true; + if(newCapacity < 0) + { + expected = false; + } + + bool result = manager.ChangeCapcity(newCapacity); + + Assert.That(result == expected); + } + + + + [TestCase("Bagel", "Onion", 5.0, 2, true)] + [TestCase("Bagol", "Onion", 5.0, 2, false)] + [TestCase("Bagel", "Pineapple", 5.0, 2, false)] + [TestCase("Bagel", "Onion", 0.1, 2, false)] + [TestCase("Bagel", "Onion", 5.0, 22, false)] + [TestCase("Coffee", "Black", 5.0, 2, true)] + [TestCase("Filling", "Bacon", 5.0, 2, true)] + [TestCase("Filling", "Egg", 5.0, 0, true)] + public void TestConfirmOrder(string name, string variant, double remainingFunds, int basketSize, bool expected) + { + Manager manager = new Manager(); + //if no filling, string filling = string.empty + + bool result = manager.ConfirmOrder(name, variant, remainingFunds, basketSize); + + Assert.That(result == expected); + } + } +} diff --git a/exercise.tests/ReceiptTest.cs b/exercise.tests/ReceiptTest.cs new file mode 100644 index 00000000..1a9e1ef0 --- /dev/null +++ b/exercise.tests/ReceiptTest.cs @@ -0,0 +1,57 @@ +using exercise.main; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + public class ReceiptTest + { + + [TestCase(2, 3, false)] + [TestCase(1, 7, true)] + [TestCase(8, 3, false)] + [TestCase(16, 7, false)] + [TestCase(12, 5, true)] + [TestCase(0, 0, false)] + [TestCase(15, 33, false)] + public void TestPrintReceipt(int buyBagel, int buyCoffee, bool filling) + { + Customer customer = new Customer(2222.0); + Basket basket = new Basket(); + + + + for(int i = 0; i < buyBagel; i++) + { + customer.AddToBasket("Bagel", "Onion"); + customer.AddToBasket("Bagel", "Everything"); + customer.AddToBasket("Bagel", "Everything"); + if (filling) + { + customer.AddToBasket("Bagel", "Sesame", "Bacon"); + } + } + for(int i = 0; i < buyCoffee; i++) + { + customer.AddToBasket("Coffee", "Black"); + customer.AddToBasket("Coffee", "Black"); + customer.AddToBasket("Coffee", "Latte"); + } + // now our customer is ready to order + + bool result = customer.Purchase(); + + if(buyBagel <= 0 && buyCoffee <= 0) //nothing in cart + { + Assert.That(result, Is.False); + } + else + { + Assert.That(result, Is.True); + } + } + } +} diff --git a/exercise.tests/UnitTest1.cs b/exercise.tests/UnitTest1.cs deleted file mode 100644 index 7bdb8968..00000000 --- a/exercise.tests/UnitTest1.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace exercise.tests; - -public class Tests -{ - [SetUp] - public void Setup() - { - } - - [Test] - public void Test1() - { - Assert.Pass(); - } -} \ No newline at end of file diff --git a/exercise.tests/exercise.tests.csproj b/exercise.tests/exercise.tests.csproj index 0072a6d1..fb313e62 100644 --- a/exercise.tests/exercise.tests.csproj +++ b/exercise.tests/exercise.tests.csproj @@ -1,4 +1,4 @@ - + net8.0 @@ -17,4 +17,8 @@ + + + +