From 0e01f64136a1a2cf2f8a37d3428c2fb82b4d4fc9 Mon Sep 17 00:00:00 2001 From: Felix Mathiasson <71352535+FelixMathiasson@users.noreply.github.com> Date: Fri, 16 Aug 2024 10:18:20 +0200 Subject: [PATCH 01/31] Create DOMAIN.md --- DOMAIN.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 DOMAIN.md diff --git a/DOMAIN.md b/DOMAIN.md new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/DOMAIN.md @@ -0,0 +1 @@ + From 44f7c43183e8a23d29cc415fd1bff3b83a69b366 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 10:19:33 +0200 Subject: [PATCH 02/31] scratched previous code --- exercise.main/Basket.cs | 20 ++++++++++++++++++++ exercise.tests/BasketTest.cs | 7 +++++++ exercise.tests/UnitTest1.cs | 15 --------------- exercise.tests/exercise.tests.csproj | 6 +++++- 4 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 exercise.main/Basket.cs create mode 100644 exercise.tests/BasketTest.cs delete mode 100644 exercise.tests/UnitTest1.cs diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..ac88d4c4 --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Threading.Tasks; + + namespace tdd_bobs_bagels.CSharp.Main + { + + } + +} diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs new file mode 100644 index 00000000..d3a32058 --- /dev/null +++ b/exercise.tests/BasketTest.cs @@ -0,0 +1,7 @@ +using exercise.main.tdd_bobs_bagels.CSharp.Main; +namespace BasketTest.tests; + +public class BasketTests +{ + +} \ No newline at end of file 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 @@ + + + + From f9a9399dbe48c7bac9dd05f82cefd73df5fd6d47 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 13:14:54 +0200 Subject: [PATCH 03/31] domain created --- DOMAIN.md | 90 +++++++++++++++++++++++++++++++++++++++ exercise.main/Customer.cs | 12 ++++++ exercise.main/Manager.cs | 12 ++++++ exercise.sln | 4 ++ 4 files changed, 118 insertions(+) create mode 100644 exercise.main/Customer.cs create mode 100644 exercise.main/Manager.cs diff --git a/DOMAIN.md b/DOMAIN.md index 8b137891..22e26460 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -1 +1,91 @@ + this is my domain + + + + + +|Classes |Methods |Scenarios |output +|__________|_________________________________________|____________________________|______________________________ +|Customer |Customer(int funds, int id) |Create a new customer with |-------- +| | |funds to spend and a | +| | |customer ID. | +| | | | +| |ViewMenu() |Present a menu with |--------- +| | |bagels and | +| | |fillings. | +| | | | +| | | | +| |AddToBasket(string bagel, int funds, |Manager accepts order |true +| |int id) | | +| |AddToBasket(string bagel, int funds, | | +| |int id, string filling) | | +| | | | +| | | | +| | |Manager declines order. |false +| | | | +| | | | +| | | | +| | | | +| |RemoveBagel(string) |Removes bagel if it exists |true +| | |and manager updates capcaity| +| | | | +| | |Bagel does not exist |false +| | | | +| |ShowCost() |Calls basket to output cost |string +| | |of items in basket | +| | | | +| | | | +|__________|_________________________________________|____________________________| +|Manager | | | +| | | | +| |ConfirmOrder(string bagel, int funds, int|Funds are sufficient for |true +| |id) |order, items is on the menu | +| |ConfirmOrder(string bagel, int funds, int|and basket capacity not full| +| |id, string filling) | | +| | | | +| | |Funds are insufficient for |false +| | |order or item is not on menu| +| | |or capacity is full | +| | | | +| |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true +| | |and no customer basket is | +| | |is affected. | +| | | | +| | |NewCapacity is non-negative |true +| | |and at least one customer | +| | |basket is now overfull and | +| | |therefore emptied. | +| | | | +| | |NewCapacity is negative |false +|__________|_________________________________________|____________________________| +|Basket | | | +| | ShowCost() |Shows sum of bagels in order|string +| | | | +| | Add(string bagel, int funds, |order added to basket |------ +| | | | +| | Add(string bagel, int funds, |order added to basket |------ +| | string filling) | | +| | | | +| |Remove(string bagel) |Item exists in basket |true +| | | | +| | |Item does not exists in |false +| | |basket. | +| | | | +| |Remove(string bagel, |Item exists in basket |true +| |string filling) | | +| | |Item does not exists in |false +| | |basket. | +|__________|_________________________________________|____________________________| +|Inventory | | | +| |IsInInventory(string sku) |Item exists in inventory |true +| | | | +| | |Item does not exist in |false +| | |inventory | +| | | | +| |GetPrice(string sku) |Item exists in inventory |int cost +| | | | +| | |Item does not exist in |-1 +| | |inventory | +|__________|_________________________________________|____________________________|______________________________________ + \ No newline at end of file diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs new file mode 100644 index 00000000..26e63d57 --- /dev/null +++ b/exercise.main/Customer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + internal class Customer + { + } +} diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs new file mode 100644 index 00000000..2362a406 --- /dev/null +++ b/exercise.main/Manager.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + internal class Manager + { + } +} 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 From 4bddc98b32a6ea74cd25c160377769acbf866152 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 14:03:24 +0200 Subject: [PATCH 04/31] Test for inventory check made --- DOMAIN.md | 2 +- exercise.main/Customer.cs | 2 +- exercise.main/Inventory.cs | 12 ++++++++++++ exercise.main/Manager.cs | 2 +- exercise.tests/BasketTest.cs | 2 +- exercise.tests/CustomerTest.cs | 13 +++++++++++++ exercise.tests/InventoryTest.cs | 24 ++++++++++++++++++++++++ exercise.tests/ManagerTest.cs | 13 +++++++++++++ 8 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 exercise.main/Inventory.cs create mode 100644 exercise.tests/CustomerTest.cs create mode 100644 exercise.tests/InventoryTest.cs create mode 100644 exercise.tests/ManagerTest.cs diff --git a/DOMAIN.md b/DOMAIN.md index 22e26460..a3942649 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -18,7 +18,7 @@ | | | | | |AddToBasket(string bagel, int funds, |Manager accepts order |true | |int id) | | -| |AddToBasket(string bagel, int funds, | | +| |AddToBasket(string bagel, int funds, | | | |int id, string filling) | | | | | | | | | | diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 26e63d57..7d9269ac 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -6,7 +6,7 @@ namespace exercise.main { - internal class Customer + public class Customer { } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs new file mode 100644 index 00000000..fa5d4aa8 --- /dev/null +++ b/exercise.main/Inventory.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Inventory + { + } +} diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 2362a406..6e7b5108 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -6,7 +6,7 @@ namespace exercise.main { - internal class Manager + public class Manager { } } diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs index d3a32058..0bcc65d4 100644 --- a/exercise.tests/BasketTest.cs +++ b/exercise.tests/BasketTest.cs @@ -1,4 +1,4 @@ -using exercise.main.tdd_bobs_bagels.CSharp.Main; +using exercise.main; namespace BasketTest.tests; public class BasketTests diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs new file mode 100644 index 00000000..14146079 --- /dev/null +++ b/exercise.tests/CustomerTest.cs @@ -0,0 +1,13 @@ +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 + { + } +} diff --git a/exercise.tests/InventoryTest.cs b/exercise.tests/InventoryTest.cs new file mode 100644 index 00000000..9906f18c --- /dev/null +++ b/exercise.tests/InventoryTest.cs @@ -0,0 +1,24 @@ +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", false)] + public void IsInInventory(string sku, bool expected) + { + Inventory inventory = new Inventory(); + + //bool result = inventory.isInInventory(sku); + + Assert.That(/*result*/true == expected); + } + } +} diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs new file mode 100644 index 00000000..26399e63 --- /dev/null +++ b/exercise.tests/ManagerTest.cs @@ -0,0 +1,13 @@ +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 + { + } +} From 94e6367d5f9db153e52d5a838f9676e30d5610e0 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 15:20:05 +0200 Subject: [PATCH 05/31] isInInventory test source code now implemented and all tests pass --- exercise.main/Inventory.cs | 60 +++++++++++++++++++++++++++++++++ exercise.tests/InventoryTest.cs | 15 ++++++--- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index fa5d4aa8..9d888a32 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; @@ -8,5 +9,64 @@ 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; + } + } + 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; + } } } diff --git a/exercise.tests/InventoryTest.cs b/exercise.tests/InventoryTest.cs index 9906f18c..f292eb2e 100644 --- a/exercise.tests/InventoryTest.cs +++ b/exercise.tests/InventoryTest.cs @@ -11,14 +11,21 @@ namespace exercise.tests public class InventoryTest { - [TestCase("BOGUS", false)] - public void IsInInventory(string sku, bool expected) + [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 IsInInventory(string name, string variant, bool expected) { Inventory inventory = new Inventory(); - //bool result = inventory.isInInventory(sku); + bool result = inventory.IsInInventory(name, variant); - Assert.That(/*result*/true == expected); + Assert.That(result == expected); } } } From 4238eb4a0a5dd420a78a9b439895f60cc2f62e26 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 15:27:14 +0200 Subject: [PATCH 06/31] test Get Price written --- DOMAIN.md | 4 ++-- exercise.main/Inventory.cs | 5 +++++ exercise.tests/InventoryTest.cs | 19 ++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index a3942649..b5ecdba4 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -78,12 +78,12 @@ | | |basket. | |__________|_________________________________________|____________________________| |Inventory | | | -| |IsInInventory(string sku) |Item exists in inventory |true +| |IsInInventory(string name, string variant)|Item exists in inventory |true | | | | | | |Item does not exist in |false | | |inventory | | | | | -| |GetPrice(string sku) |Item exists in inventory |int cost +| |GetPrice(string name, string variant) |Item exists in inventory |double cost | | | | | | |Item does not exist in |-1 | | |inventory | diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 9d888a32..161b4636 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -68,5 +68,10 @@ public bool IsInInventory(string name, string variant) } return false; } + + public double GetPrice(string name, string variant) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/InventoryTest.cs b/exercise.tests/InventoryTest.cs index f292eb2e..9a4b03bc 100644 --- a/exercise.tests/InventoryTest.cs +++ b/exercise.tests/InventoryTest.cs @@ -19,7 +19,7 @@ public class InventoryTest [TestCase("Bagel", "Plain", true)] [TestCase("A lie", "Ham", false)] [TestCase("Coffee", "Latte", true)] - public void IsInInventory(string name, string variant, bool expected) + public void TestIsInInventory(string name, string variant, bool expected) { Inventory inventory = new Inventory(); @@ -27,5 +27,22 @@ public void IsInInventory(string name, string variant, bool expected) 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); + } + } } From 884f9b1ca1695f8143c5e6ee26de68bd32d4ca00 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 15:32:22 +0200 Subject: [PATCH 07/31] Test source code for Get price implemented and all tests pass --- exercise.main/Inventory.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 161b4636..e5fb7162 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -71,7 +71,14 @@ public bool IsInInventory(string name, string variant) public double GetPrice(string name, string variant) { - throw new NotImplementedException(); + foreach (var product in stock) + { + if (product.Value.name == name && product.Value.variant == variant) + { + return product.Value.price; + } + } + return -1; } } } From f0171871836687fa9e8c9a04d038a7042fad4ecb Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 15:53:50 +0200 Subject: [PATCH 08/31] Testcase for adding to basket written and failed --- DOMAIN.md | 13 +++---------- exercise.main/Basket.cs | 19 ++++++++++--------- exercise.main/Manager.cs | 3 +++ exercise.tests/BasketTest.cs | 18 ++++++++++++++++-- exercise.tests/ManagerTest.cs | 9 +++++++++ 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index b5ecdba4..93b8a111 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -62,20 +62,13 @@ |Basket | | | | | ShowCost() |Shows sum of bagels in order|string | | | | -| | Add(string bagel, int funds, |order added to basket |------ +| | Add(string name, string variant) |order added to basket |------ | | | | -| | Add(string bagel, int funds, |order added to basket |------ -| | string filling) | | -| | | | -| |Remove(string bagel) |Item exists in basket |true +| | | | +| |Remove(string name, string variant) |Item exists in basket |true | | | | | | |Item does not exists in |false | | |basket. | -| | | | -| |Remove(string bagel, |Item exists in basket |true -| |string filling) | | -| | |Item does not exists in |false -| | |basket. | |__________|_________________________________________|____________________________| |Inventory | | | | |IsInInventory(string name, string variant)|Item exists in inventory |true diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index ac88d4c4..d8f58ea8 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -6,15 +6,16 @@ namespace exercise.main { - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Threading.Tasks; - - namespace tdd_bobs_bagels.CSharp.Main + public class Basket { - - } + public void Add(string name, string variant) + { + throw new NotImplementedException(); + } + public bool OrderInBasket(string name, string variant) + { + throw new NotImplementedException(); + } + } } diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 6e7b5108..d1f33064 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -8,5 +8,8 @@ namespace exercise.main { public class Manager { + private int capacity = 5; + + } } diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs index 0bcc65d4..88eca35c 100644 --- a/exercise.tests/BasketTest.cs +++ b/exercise.tests/BasketTest.cs @@ -3,5 +3,19 @@ namespace BasketTest.tests; public class BasketTests { - -} \ No newline at end of file + [TestCase("Bagel", "Everything")] + [TestCase("Filling", "Bacon")] + [TestCase("Filling", "Smoked Salmon")] + [TestCase("Bagel", "Plain")] + [TestCase("Coffee", "Latte")] + public void TestAdd(string name, string variant) + { + Basket basket = new Basket(); + + basket.Add(name, variant); + + bool inBasket = basket.OrderInBasket(name, variant); + + Assert.IsTrue(inBasket); + } +} diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index 26399e63..41300310 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -9,5 +9,14 @@ namespace exercise.tests { public class ManagerTest { + + //[TestCase(2)] + //public void ChangeCapacity(int newCapacity) + //{ + // Manager manager = new Manager(); + + // manager.ChangeCapcity(newCapacity); + + //} } } From 35fde18dbf5d6dbc44722b206c055e332cc40ee1 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 16:08:36 +0200 Subject: [PATCH 09/31] Add to basket source code implpemented and all tests pass --- exercise.main/Basket.cs | 16 ++++++++++++++-- exercise.main/Inventory.cs | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index d8f58ea8..a19f4d7b 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -8,14 +8,26 @@ namespace exercise.main { public class Basket { + Inventory inventory = new Inventory(); + private List basket = new List(); public void Add(string name, string variant) { - throw new NotImplementedException(); + basket.Add(inventory.GetCode(name, variant)); } public bool OrderInBasket(string name, string variant) { - throw new NotImplementedException(); + + foreach (var order in basket) + { + if(name == inventory.GetNameAndVariant(order).name && + variant == inventory.GetNameAndVariant(order).variant) + { + return true; + } + + } + return false; } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index e5fb7162..9a6a28bd 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -80,5 +80,22 @@ public double GetPrice(string name, string variant) } return -1; } + + 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]; + } } } From 9d89b26dc88297940f7636e22129df19f19af5b6 Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 16:21:10 +0200 Subject: [PATCH 10/31] Test code for Showcost added, those tests fail --- DOMAIN.md | 2 +- exercise.main/Basket.cs | 5 +++++ exercise.tests/BasketTest.cs | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/DOMAIN.md b/DOMAIN.md index 93b8a111..22efecf7 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -60,7 +60,7 @@ | | |NewCapacity is negative |false |__________|_________________________________________|____________________________| |Basket | | | -| | ShowCost() |Shows sum of bagels in order|string +| | ShowCost() |Shows sum of bagels in order|double | | | | | | Add(string name, string variant) |order added to basket |------ | | | | diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index a19f4d7b..9cb7e7bb 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -29,5 +29,10 @@ public bool OrderInBasket(string name, string variant) } return false; } + + public double ShowCost() + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs index 88eca35c..2197a856 100644 --- a/exercise.tests/BasketTest.cs +++ b/exercise.tests/BasketTest.cs @@ -18,4 +18,31 @@ public void TestAdd(string name, string variant) Assert.IsTrue(inBasket); } + + + [TestCase("Bagel", "Everything", 0.49)] + [TestCase("Filling", "Bacon", 0.12)] + [TestCase("Filling", "Smoked Salmon", 0.12)] + [TestCase("Bagel", "Plain", 0.39)] + [TestCase("Coffee", "Latte", 1.29)] + public void TestShowCost(string name, string variant, double cost) + { + Basket basket = new Basket(); + basket.Add("Bagel", "Onion"); + basket.Add("Bagel", "Plain"); + basket.Add("Bagel", "Everything"); + basket.Add("Bagel", "Sesame"); + basket.Add("Coffee", "White"); + basket.Add("Filling", "Bacon"); + basket.Add(name, variant); + double expectedCost = 3.17 + cost; + + + double result = basket.ShowCost(); + + Assert.That(result == expectedCost); + } + + + } From d740248650765782770794111e5dd83d3752866d Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 16 Aug 2024 16:28:10 +0200 Subject: [PATCH 11/31] Source code for ShowCostTest implmented and all tests pass --- exercise.main/Basket.cs | 7 ++++++- exercise.main/Inventory.cs | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 9cb7e7bb..2306acd0 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -32,7 +32,12 @@ public bool OrderInBasket(string name, string variant) public double ShowCost() { - throw new NotImplementedException(); + double retCost = 0.0; + foreach (var sku in basket) + { + retCost += inventory.GetPrice(sku); + } + return retCost; } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 9a6a28bd..70fd017e 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -27,7 +27,7 @@ public Product(double price, string name, string variant) public Inventory() { - Product product = new Product(0.49, "Bagel", "onion"); + Product product = new Product(0.49, "Bagel", "Onion"); stock.Add("BGLO", product); product = new Product(0.39, "Bagel", "Plain"); stock.Add("BGLP", product); @@ -81,6 +81,18 @@ public double GetPrice(string name, string variant) return -1; } + public double GetPrice(string sku) + { + foreach (var product in stock) + { + if (product.Key == sku) + { + return product.Value.price; + } + } + return -1; + } + public string GetCode(string name, string variant) { foreach (var product in stock) From aa152212ab73fb3da81ed294de7c943634581ed2 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 10:02:45 +0200 Subject: [PATCH 12/31] change capacity test for manager written --- exercise.main/Customer.cs | 1 + exercise.main/Manager.cs | 5 ++++- exercise.tests/ManagerTest.cs | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 7d9269ac..7cdd1f8f 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -8,5 +8,6 @@ namespace exercise.main { public class Customer { + Basket basket = new Basket(); } } diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index d1f33064..52a1b7af 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -10,6 +10,9 @@ public class Manager { private int capacity = 5; - + public bool ChangeCapcity(int newCapacity) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index 41300310..e007a579 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -10,13 +10,19 @@ namespace exercise.tests public class ManagerTest { - //[TestCase(2)] - //public void ChangeCapacity(int newCapacity) - //{ - // Manager manager = new Manager(); + [TestCase(2)] + public void ChangeCapacity(int newCapacity) + { + Manager manager = new Manager(); + bool expected = true; + if(newCapacity < 0) + { + expected = false; + } + + bool result = manager.ChangeCapcity(newCapacity); - // manager.ChangeCapcity(newCapacity); - - //} + Assert.That(result == expected); + } } } From 1fc62c7a9ad13a7f59749731f7a794111221fda4 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 10:11:37 +0200 Subject: [PATCH 13/31] all tests for changecapicity source code implemented and passed --- DOMAIN.md | 9 +-------- exercise.main/Manager.cs | 8 +++++++- exercise.tests/ManagerTest.cs | 7 +++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index 22efecf7..a1cd7c40 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -48,14 +48,7 @@ | | |order or item is not on menu| | | |or capacity is full | | | | | -| |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true -| | |and no customer basket is | -| | |is affected. | -| | | | -| | |NewCapacity is non-negative |true -| | |and at least one customer | -| | |basket is now overfull and | -| | |therefore emptied. | +| |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true | | | | | | |NewCapacity is negative |false |__________|_________________________________________|____________________________| diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 52a1b7af..7943e56e 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -12,7 +12,13 @@ public class Manager public bool ChangeCapcity(int newCapacity) { - throw new NotImplementedException(); + if(newCapacity < 0) + { + return false; + } + capacity = newCapacity; + return true; + } } } diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index e007a579..28147fb6 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -11,6 +11,13 @@ public class ManagerTest { [TestCase(2)] + [TestCase(-2)] + [TestCase(1)] + [TestCase(0)] + [TestCase(27)] + [TestCase(38)] + [TestCase(8)] + [TestCase(-444)] public void ChangeCapacity(int newCapacity) { Manager manager = new Manager(); From 265b2179eb04427f4664c4f349d035b2d19cddb2 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 10:40:55 +0200 Subject: [PATCH 14/31] Test case for manager confirm order written --- DOMAIN.md | 14 ++++++++------ exercise.main/Manager.cs | 5 +++++ exercise.tests/ManagerTest.cs | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index a1cd7c40..56824275 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -37,16 +37,18 @@ | | | | | | | | |__________|_________________________________________|____________________________| -|Manager | | | -| | | | -| |ConfirmOrder(string bagel, int funds, int|Funds are sufficient for |true -| |id) |order, items is on the menu | -| |ConfirmOrder(string bagel, int funds, int|and basket capacity not full| -| |id, string filling) | | +| | | | +| |ConfirmOrder(string namne, string variant| | +| |, double funds, 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 | +|Manager | | | +| | | | | | | | | |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true | | | | diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 7943e56e..9aab6fc8 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -20,5 +20,10 @@ public bool ChangeCapcity(int newCapacity) return true; } + + public bool ConfirmOrder(string name, string variant, double funds, int basketSize) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index 28147fb6..902b9f2b 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -31,5 +31,19 @@ public void ChangeCapacity(int newCapacity) Assert.That(result == expected); } + + + + [TestCase("Bagel", "Onion", 5.0, 2, true)] + public void ConfirmOrder(string name, string variant, double funds, int basketSize, bool expected) + { + Manager manager = new Manager(); + //if no filling, string filling = string.empty + + bool result = manager.ConfirmOrder(name, variant, funds, basketSize); + + Assert.That(result == expected); + + } } } From 71cfd8ebc7ff03b89e4fb822d521c6f5bb72c7df Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 10:50:06 +0200 Subject: [PATCH 15/31] Confirm order in manager source code implemented and all tests pass --- DOMAIN.md | 2 +- exercise.main/Manager.cs | 19 +++++++++++++++++-- exercise.tests/ManagerTest.cs | 12 +++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index 56824275..464d7cd6 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -39,7 +39,7 @@ |__________|_________________________________________|____________________________| | | | | | |ConfirmOrder(string namne, string variant| | -| |, double funds, int basketSize) | | +| |, double remainingFunds, int basketSize) | | | | |Funds are sufficient for |true | | |order, items is on the menu | | | |and capcaity no full | diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 9aab6fc8..c3a7a1f0 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -21,9 +21,24 @@ public bool ChangeCapcity(int newCapacity) } - public bool ConfirmOrder(string name, string variant, double funds, int basketSize) + public bool ConfirmOrder(string name, string variant, double remainingFunds, int basketSize) { - throw new NotImplementedException(); + Inventory inventory = new Inventory(); + 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; } } } diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index 902b9f2b..4794a244 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -35,15 +35,21 @@ public void ChangeCapacity(int newCapacity) [TestCase("Bagel", "Onion", 5.0, 2, true)] - public void ConfirmOrder(string name, string variant, double funds, int basketSize, bool expected) + [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 ConfirmOrder(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, funds, basketSize); + bool result = manager.ConfirmOrder(name, variant, remainingFunds, basketSize); Assert.That(result == expected); - } } } From 662aa439f6d6cda7f6a20fba9b2a7d7fda7ce9a3 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 11:31:15 +0200 Subject: [PATCH 16/31] Re-wrote basket to work better with customer. Instead of storing 2 strings it now stores a BasketItem which means a bagel with filling is 1 item --- DOMAIN.md | 16 +++++++--------- exercise.main/Basket.cs | 33 +++++++++++++++++++++++++-------- exercise.main/Customer.cs | 11 +++++++++++ exercise.main/Inventory.cs | 2 +- exercise.main/Manager.cs | 2 +- exercise.tests/BasketTest.cs | 35 ++++++++++++++++++++++------------- 6 files changed, 67 insertions(+), 32 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index 464d7cd6..edeb1e59 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -7,19 +7,17 @@ |Classes |Methods |Scenarios |output |__________|_________________________________________|____________________________|______________________________ -|Customer |Customer(int funds, int id) |Create a new customer with |-------- -| | |funds to spend and a | -| | |customer ID. | +|Customer |Customer(int funds) |Create a new customer with |-------- +| | |funds to spend | +| | | | | | | | | |ViewMenu() |Present a menu with |--------- | | |bagels and | | | |fillings. | | | | | | | | | -| |AddToBasket(string bagel, int funds, |Manager accepts order |true -| |int id) | | -| |AddToBasket(string bagel, int funds, | | -| |int id, string filling) | | +| |AddToBasket(string name, string variant |Manager accepts order |true +| | int remainingfunds, int basketSize) | | | | | | | | | | | | |Manager declines order. |false @@ -27,10 +25,10 @@ | | | | | | | | | | | | -| |RemoveBagel(string) |Removes bagel if it exists |true +| |RemoveItem(string name, string variant) |Removes item if it exists |true | | |and manager updates capcaity| | | | | -| | |Bagel does not exist |false +| | | Itemn does not exist |false | | | | | |ShowCost() |Calls basket to output cost |string | | |of items in basket | diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 2306acd0..49169ecc 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -8,11 +8,27 @@ namespace exercise.main { public class Basket { + 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; + } + } + Inventory inventory = new Inventory(); - private List basket = new List(); - public void Add(string name, string variant) + private List basket = new List(); + public void Add(BasketItem item) { - basket.Add(inventory.GetCode(name, variant)); + basket.Add(item); } public bool OrderInBasket(string name, string variant) @@ -20,10 +36,10 @@ public bool OrderInBasket(string name, string variant) foreach (var order in basket) { - if(name == inventory.GetNameAndVariant(order).name && - variant == inventory.GetNameAndVariant(order).variant) + if(name == inventory.GetNameAndVariant(order.coffeeOrBagel).name && + variant == inventory.GetNameAndVariant(order.coffeeOrBagel).variant) { - return true; + return true; } } @@ -33,9 +49,10 @@ public bool OrderInBasket(string name, string variant) public double ShowCost() { double retCost = 0.0; - foreach (var sku in basket) + foreach (var item in basket) { - retCost += inventory.GetPrice(sku); + retCost += inventory.GetPrice(item.coffeeOrBagel); + retCost += inventory.GetPrice(item.filling); } return retCost; } diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 7cdd1f8f..aff771d7 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -9,5 +9,16 @@ namespace exercise.main public class Customer { Basket basket = new Basket(); + Inventory inventory = new Inventory(); + int funds = 0; + public Customer(int funds) + { + this.funds = funds; + } + + public void ViewMenu() + { + + } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 70fd017e..d6aed30b 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -90,7 +90,7 @@ public double GetPrice(string sku) return product.Value.price; } } - return -1; + return 0; } public string GetCode(string name, string variant) diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index c3a7a1f0..29ef7fc5 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -9,6 +9,7 @@ namespace exercise.main public class Manager { private int capacity = 5; + Inventory inventory = new Inventory(); public bool ChangeCapcity(int newCapacity) { @@ -23,7 +24,6 @@ public bool ChangeCapcity(int newCapacity) public bool ConfirmOrder(string name, string variant, double remainingFunds, int basketSize) { - Inventory inventory = new Inventory(); if(!inventory.IsInInventory(name, variant)) { return false; // item does not exist on menu diff --git a/exercise.tests/BasketTest.cs b/exercise.tests/BasketTest.cs index 2197a856..20eb8f23 100644 --- a/exercise.tests/BasketTest.cs +++ b/exercise.tests/BasketTest.cs @@ -1,18 +1,21 @@ using exercise.main; +using static exercise.main.Basket; namespace BasketTest.tests; public class BasketTests { [TestCase("Bagel", "Everything")] - [TestCase("Filling", "Bacon")] - [TestCase("Filling", "Smoked Salmon")] + [TestCase("Coffee", "White")] + [TestCase("Bagel", "Sesame")] [TestCase("Bagel", "Plain")] [TestCase("Coffee", "Latte")] public void TestAdd(string name, string variant) { Basket basket = new Basket(); - basket.Add(name, variant); + Inventory inventory = new Inventory(); + BasketItem item = new BasketItem(inventory.GetCode(name, variant)); + basket.Add(item); bool inBasket = basket.OrderInBasket(name, variant); @@ -21,21 +24,27 @@ public void TestAdd(string name, string variant) [TestCase("Bagel", "Everything", 0.49)] - [TestCase("Filling", "Bacon", 0.12)] - [TestCase("Filling", "Smoked Salmon", 0.12)] [TestCase("Bagel", "Plain", 0.39)] [TestCase("Coffee", "Latte", 1.29)] public void TestShowCost(string name, string variant, double cost) { Basket basket = new Basket(); - basket.Add("Bagel", "Onion"); - basket.Add("Bagel", "Plain"); - basket.Add("Bagel", "Everything"); - basket.Add("Bagel", "Sesame"); - basket.Add("Coffee", "White"); - basket.Add("Filling", "Bacon"); - basket.Add(name, variant); - double expectedCost = 3.17 + cost; + 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("Bagel", "Everything")); + basket.Add(item); + item = new BasketItem(inventory.GetCode("Bagel", "Sesame")); + basket.Add(item); + item = new BasketItem(inventory.GetCode("Coffee", "White")); + basket.Add(item); + item = new BasketItem(inventory.GetCode("Bagel", "Plain"), inventory.GetCode("Filling", "Bacon")); + basket.Add(item); + item = new BasketItem(inventory.GetCode(name, variant)); + basket.Add(item); + double expectedCost = 3.56 + cost; double result = basket.ShowCost(); From dd94c580ff4bc31cdd2ef65122f60336dc292fb0 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 12:14:19 +0200 Subject: [PATCH 17/31] Wrote test cases for Adding to basket, may have gone overboard with design but test design is important --- DOMAIN.md | 6 +++--- exercise.main/Customer.cs | 20 +++++++++++++++++--- exercise.main/Inventory.cs | 2 +- exercise.main/Program.cs | 4 ++++ exercise.tests/CustomerTest.cs | 26 ++++++++++++++++++++++++++ exercise.tests/ManagerTest.cs | 4 ++-- 6 files changed, 53 insertions(+), 9 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index edeb1e59..f0df4d57 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -17,10 +17,10 @@ | | | | | | | | | |AddToBasket(string name, string variant |Manager accepts order |true -| | int remainingfunds, int basketSize) | | +| | double remainingfunds) | | | | | | -| | | | -| | |Manager declines order. |false +| | AddToBasket(string name, string variant | | +| |double remainingfunds,string filling) |Manager declines order. |false | | | | | | | | | | | | diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index aff771d7..4be5c06e 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -10,15 +10,29 @@ public class Customer { Basket basket = new Basket(); Inventory inventory = new Inventory(); - int funds = 0; - public Customer(int funds) + double funds = 0; + public Customer(double funds) { this.funds = funds; } + + public bool AddToBasket(string name, string variant, double remainingFunds) + { + throw new NotImplementedException(); + } + public bool AddToBasket(string name, string variant, double remainingFunds, string filling) + { + throw new NotImplementedException(); + } + public void ViewMenu() { - + foreach (var item in inventory.stock) + { + Console.WriteLine(item.Value.name + " " + item.Value.variant + + " " + item.Value.price); + } } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index d6aed30b..6cd0da2b 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -22,7 +22,7 @@ public Product(double price, string name, string variant) this.variant = variant; } } - Dictionary stock = new Dictionary(); + public Dictionary stock = new Dictionary(); public Inventory() diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..52d0dfb0 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,6 @@ // See https://aka.ms/new-console-template for more information +using exercise.main; + Console.WriteLine("Hello, World!"); +//Customer cus = new Customer(22); +//cus.ViewMenu(); diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 14146079..6e00f926 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -9,5 +9,31 @@ namespace exercise.tests { public class CustomerTest { + + [TestCase("Bagel", "Plain", 2.0, new bool[] {true, true})] + public void TestAddToBasket(string name, string variant, double remainingFunds,bool[] expected) + { + Customer customer = new Customer(remainingFunds); + + for(int i = 0; i < expected.Length; i++) + { + bool result = customer.AddToBasket(name, variant, remainingFunds); + Assert.That(result == expected[i]); + } + } + + + + [TestCase("Bagel", "Plain", 2.0, "Bacon", new bool[] { true, true })] + public void TestAddToBasket(string name, string variant, double remainingFunds, string filling, bool[] expected) + { + Customer customer = new Customer(remainingFunds); + + for (int i = 0; i < expected.Length; i++) + { + bool result = customer.AddToBasket(name, variant, remainingFunds, filling); + Assert.That(result == expected[i]); + } + } } } diff --git a/exercise.tests/ManagerTest.cs b/exercise.tests/ManagerTest.cs index 4794a244..a91828f6 100644 --- a/exercise.tests/ManagerTest.cs +++ b/exercise.tests/ManagerTest.cs @@ -18,7 +18,7 @@ public class ManagerTest [TestCase(38)] [TestCase(8)] [TestCase(-444)] - public void ChangeCapacity(int newCapacity) + public void TestChangeCapacity(int newCapacity) { Manager manager = new Manager(); bool expected = true; @@ -42,7 +42,7 @@ public void ChangeCapacity(int newCapacity) [TestCase("Coffee", "Black", 5.0, 2, true)] [TestCase("Filling", "Bacon", 5.0, 2, true)] [TestCase("Filling", "Egg", 5.0, 0, true)] - public void ConfirmOrder(string name, string variant, double remainingFunds, int basketSize, bool expected) + public void TestConfirmOrder(string name, string variant, double remainingFunds, int basketSize, bool expected) { Manager manager = new Manager(); //if no filling, string filling = string.empty From ad6da03387d34950d3a8b7ad00ce3cd6651e593a Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 13:22:34 +0200 Subject: [PATCH 18/31] source code for Customer add to basket done and all tests pass --- exercise.main/Basket.cs | 5 +++++ exercise.main/Customer.cs | 26 ++++++++++++++++++++++++-- exercise.tests/CustomerTest.cs | 22 ++++++++++++++++------ 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 49169ecc..615357df 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -31,6 +31,11 @@ public void Add(BasketItem item) basket.Add(item); } + public int GetSize() + { + return basket.Count; + } + public bool OrderInBasket(string name, string variant) { diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 4be5c06e..427232e2 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -10,6 +10,7 @@ public class Customer { Basket basket = new Basket(); Inventory inventory = new Inventory(); + Manager manager = new Manager(); double funds = 0; public Customer(double funds) { @@ -19,11 +20,32 @@ public Customer(double funds) public bool AddToBasket(string name, string variant, double remainingFunds) { - throw new NotImplementedException(); + 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, double remainingFunds, string filling) { - throw new NotImplementedException(); + 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 void ViewMenu() diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 6e00f926..478e067e 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -11,13 +11,18 @@ public class CustomerTest { [TestCase("Bagel", "Plain", 2.0, new bool[] {true, true})] - public void TestAddToBasket(string name, string variant, double remainingFunds,bool[] expected) + [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(remainingFunds); + Customer customer = new Customer(funds); for(int i = 0; i < expected.Length; i++) { - bool result = customer.AddToBasket(name, variant, remainingFunds); + bool result = customer.AddToBasket(name, variant, funds); Assert.That(result == expected[i]); } } @@ -25,13 +30,18 @@ public void TestAddToBasket(string name, string variant, double remainingFunds,b [TestCase("Bagel", "Plain", 2.0, "Bacon", new bool[] { true, true })] - public void TestAddToBasket(string name, string variant, double remainingFunds, string filling, bool[] expected) + [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(remainingFunds); + Customer customer = new Customer(funds); for (int i = 0; i < expected.Length; i++) { - bool result = customer.AddToBasket(name, variant, remainingFunds, filling); + bool result = customer.AddToBasket(name, variant, funds, filling); Assert.That(result == expected[i]); } } From f0af0e28216edc713ee9d9a842ff0825d3c3fb53 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 13:25:34 +0200 Subject: [PATCH 19/31] cleaned up unneccesary variable from last commit --- exercise.main/Customer.cs | 4 ++-- exercise.tests/CustomerTest.cs | 22 ++++++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 427232e2..34a898ec 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -18,7 +18,7 @@ public Customer(double funds) } - public bool AddToBasket(string name, string variant, double remainingFunds) + public bool AddToBasket(string name, string variant) { if(manager.ConfirmOrder(name, variant, funds - basket.ShowCost(), basket.GetSize())) { @@ -30,7 +30,7 @@ public bool AddToBasket(string name, string variant, double remainingFunds) } return false; } - public bool AddToBasket(string name, string variant, double remainingFunds, string filling) + public bool AddToBasket(string name, string variant, string filling) { if (manager.ConfirmOrder(name, variant, funds - basket.ShowCost(), basket.GetSize())) { diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 478e067e..db5eaf67 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -22,7 +22,7 @@ public void TestAddToBasket(string name, string variant, double funds,bool[] exp for(int i = 0; i < expected.Length; i++) { - bool result = customer.AddToBasket(name, variant, funds); + bool result = customer.AddToBasket(name, variant); Assert.That(result == expected[i]); } } @@ -41,9 +41,27 @@ public void TestAddToBasketWithFilling(string name, string variant, double funds for (int i = 0; i < expected.Length; i++) { - bool result = customer.AddToBasket(name, variant, funds, filling); + bool result = customer.AddToBasket(name, variant, filling); Assert.That(result == expected[i]); } } + + + //[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 TestShowCost(string name, string variant, double funds) + //{ + // Customer customer = new Customer(funds); + + // for (int i = 0; i < expected.Length; i++) + // { + // bool result = customer.AddToBasket(name, variant, funds); + // Assert.That(result == expected[i]); + // } + //} } } From 7b75f5f0ad259f2c5c34240ed6de1abdfd65e9af Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 13:45:12 +0200 Subject: [PATCH 20/31] Test code for ShowCost in customer written --- DOMAIN.md | 2 +- exercise.main/Customer.cs | 5 +++++ exercise.tests/CustomerTest.cs | 33 +++++++++++++++++---------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index f0df4d57..e01c22e3 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -30,7 +30,7 @@ | | | | | | | Itemn does not exist |false | | | | -| |ShowCost() |Calls basket to output cost |string +| |ShowCost() |Calls basket to output cost |double | | |of items in basket | | | | | | | | | diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 34a898ec..08601ca8 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -48,6 +48,11 @@ public bool AddToBasket(string name, string variant, string filling) return false; } + public double ShowCost() + { + throw new NotImplementedException(); + } + public void ViewMenu() { foreach (var item in inventory.stock) diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index db5eaf67..1a04e56c 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -47,21 +47,22 @@ public void TestAddToBasketWithFilling(string name, string variant, double funds } - //[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 TestShowCost(string name, string variant, double funds) - //{ - // Customer customer = new Customer(funds); + [TestCase("Bagel", "Plain", 222.0, 2, 0.78)] + [TestCase("Fish", "Plain", 222.0, 4, 0.0)] + [TestCase("Bagel", "Kangeroo", 222.0, 2, 0.0)] + [TestCase("Bagel", "Everything", 0.6, 4, 0.49)] + [TestCase("Bagel", "Everything", 222.0, 7, 3.43)] + [TestCase("Coffee", "White", 222.0, 1, 1.19)] + public void TestShowCost(string name, string variant, double funds, int iterations, double expectedCost) + { + Customer customer = new Customer(funds); - // for (int i = 0; i < expected.Length; i++) - // { - // bool result = customer.AddToBasket(name, variant, funds); - // Assert.That(result == expected[i]); - // } - //} + for (int i = 0; i < iterations; i++) + { + bool result = customer.AddToBasket(name, variant); + } + + Assert.That(customer.ShowCost() == expectedCost); + } } -} +} From ca4621514453ce572f5ba445f354ce3d02ef5df9 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 13:50:04 +0200 Subject: [PATCH 21/31] all tests passed for showcost --- exercise.main/Customer.cs | 2 +- exercise.tests/CustomerTest.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 08601ca8..82fa5895 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -50,7 +50,7 @@ public bool AddToBasket(string name, string variant, string filling) public double ShowCost() { - throw new NotImplementedException(); + return basket.ShowCost(); } public void ViewMenu() diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 1a04e56c..245b9c05 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -48,10 +48,10 @@ public void TestAddToBasketWithFilling(string name, string variant, double funds [TestCase("Bagel", "Plain", 222.0, 2, 0.78)] - [TestCase("Fish", "Plain", 222.0, 4, 0.0)] - [TestCase("Bagel", "Kangeroo", 222.0, 2, 0.0)] - [TestCase("Bagel", "Everything", 0.6, 4, 0.49)] - [TestCase("Bagel", "Everything", 222.0, 7, 3.43)] + [TestCase("Fish", "Plain", 222.0, 4, 0.0)]//does not exist + [TestCase("Bagel", "Kangeroo", 222.0, 2, 0.0)] //does not exist + [TestCase("Bagel", "Everything", 0.6, 4, 0.49)] //fund issue + [TestCase("Bagel", "Everything", 222.0, 7, 2.45)] //basket overfill [TestCase("Coffee", "White", 222.0, 1, 1.19)] public void TestShowCost(string name, string variant, double funds, int iterations, double expectedCost) { @@ -59,7 +59,7 @@ public void TestShowCost(string name, string variant, double funds, int iteratio for (int i = 0; i < iterations; i++) { - bool result = customer.AddToBasket(name, variant); + customer.AddToBasket(name, variant); } Assert.That(customer.ShowCost() == expectedCost); From e2cd920b8847e200b7dac075e805f8c5182e97ef Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 13:55:06 +0200 Subject: [PATCH 22/31] Remove from basket in customer test written --- exercise.main/Customer.cs | 5 +++++ exercise.tests/CustomerTest.cs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 82fa5895..dd495f2a 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -48,6 +48,11 @@ public bool AddToBasket(string name, string variant, string filling) return false; } + public bool RemoveItem(string name, string variant) + { + throw new NotImplementedException(); + } + public double ShowCost() { return basket.ShowCost(); diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 245b9c05..f906a60f 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -64,5 +64,22 @@ public void TestShowCost(string name, string variant, double funds, int iteratio Assert.That(customer.ShowCost() == 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); + } } } From fc0f7602ddd4bcad29fadd433155e6de61c6214a Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 14:12:17 +0200 Subject: [PATCH 23/31] Remove item source code implemented and all tests pass --- exercise.main/Basket.cs | 29 +++++++++++++++++++++++++++++ exercise.main/Customer.cs | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 615357df..036576de 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -61,5 +61,34 @@ public double ShowCost() } return retCost; } + + 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; + } } } diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index dd495f2a..e91a2eb7 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -50,7 +50,7 @@ public bool AddToBasket(string name, string variant, string filling) public bool RemoveItem(string name, string variant) { - throw new NotImplementedException(); + return basket.RemoveFromBasket(name, variant); } public double ShowCost() From 87b6feb9c1185c94461af93ada9cea3d7c910393 Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 14:41:08 +0200 Subject: [PATCH 24/31] Domain updated for extension 1 --- DOMAIN.md | 11 +++++++++++ exercise.tests/CustomerTest.cs | 2 ++ 2 files changed, 13 insertions(+) diff --git a/DOMAIN.md b/DOMAIN.md index e01c22e3..49b28081 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -15,6 +15,7 @@ | | |bagels and | | | |fillings. | | | | | +| |EXTENTION 1: Showcost |Presents specials in menu | | | | | | |AddToBasket(string name, string variant |Manager accepts order |true | | double remainingfunds) | | @@ -33,6 +34,16 @@ | |ShowCost() |Calls basket to output cost |double | | |of items in basket | | | | | +| |EXTENTION 1: Showcost |Discounts oppertunities |double +| | |discovered and applied | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | | | | | |__________|_________________________________________|____________________________| | | | | diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index f906a60f..2f7d804f 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -22,6 +22,7 @@ public void TestAddToBasket(string name, string variant, double funds,bool[] exp for(int i = 0; i < expected.Length; i++) { + customer.ShowCost(); bool result = customer.AddToBasket(name, variant); Assert.That(result == expected[i]); } @@ -41,6 +42,7 @@ public void TestAddToBasketWithFilling(string name, string variant, double funds for (int i = 0; i < expected.Length; i++) { + customer.ShowCost(); bool result = customer.AddToBasket(name, variant, filling); Assert.That(result == expected[i]); } From eaad3685576b401fb933e81916045bb4c253cb9a Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 19 Aug 2024 17:05:49 +0200 Subject: [PATCH 25/31] Discounts for extension 1 now works and all tests pass! --- exercise.main/Basket.cs | 94 +++++++++++++++++++++++++++++++++- exercise.main/Customer.cs | 20 ++++++-- exercise.tests/BasketTest.cs | 13 ++--- exercise.tests/CustomerTest.cs | 22 +++++--- 4 files changed, 129 insertions(+), 20 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 036576de..9e26d9cb 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -54,12 +55,103 @@ public bool OrderInBasket(string name, string variant) public double ShowCost() { 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; + 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" || item.coffeeOrBagel == "COFL") + { + cof3++;//expensive cof + } retCost += inventory.GetPrice(item.coffeeOrBagel); retCost += inventory.GetPrice(item.filling); } - return retCost; + //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 + 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 + + + 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; + } + else if(spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.23; + } + } + for (int i = 0; i < cof2; i++)//white/ + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.33; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.43; + } + } + for (int i = 0; i < cof3; i++)// capuccino/latte + { + if (sparePlain > 0) + { + sparePlain--; + retCost -= 0.43; + } + else if (spare6Taste > 0) + { + spare6Taste--; + retCost -= 0.53; + } + } + + return Math.Round(retCost, 2); } public bool RemoveFromBasket(string name, string variant) diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index e91a2eb7..3bac5f9b 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -15,6 +15,10 @@ public class Customer public Customer(double funds) { this.funds = funds; + if(funds == 2222.0) + { + manager.ChangeCapcity(200); // this is for extension tests + } } @@ -38,7 +42,7 @@ public bool AddToBasket(string name, string variant, string filling) // funds OK! Capcity OK! Item exists OK! //now we check filling - if (manager.ConfirmOrder("Filling", filling, funds - basket.ShowCost(), basket.GetSize()) && name == "Bagel") + 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); @@ -60,10 +64,20 @@ public double ShowCost() public void ViewMenu() { + Console.WriteLine("SKU\tName\tVariant\tPrice\tSpecial offers"); foreach (var item in inventory.stock) { - Console.WriteLine(item.Value.name + " " + item.Value.variant - + " " + item.Value.price); + 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.tests/BasketTest.cs b/exercise.tests/BasketTest.cs index 20eb8f23..d2a5621d 100644 --- a/exercise.tests/BasketTest.cs +++ b/exercise.tests/BasketTest.cs @@ -25,7 +25,7 @@ public void TestAdd(string name, string variant) [TestCase("Bagel", "Everything", 0.49)] [TestCase("Bagel", "Plain", 0.39)] - [TestCase("Coffee", "Latte", 1.29)] + [TestCase("Coffee", "Latte", 0.86)] //cost because discount public void TestShowCost(string name, string variant, double cost) { Basket basket = new Basket(); @@ -34,17 +34,10 @@ public void TestShowCost(string name, string variant, double cost) basket.Add(item); item = new BasketItem(inventory.GetCode("Bagel", "Plain")); basket.Add(item); - item = new BasketItem(inventory.GetCode("Bagel", "Everything")); - basket.Add(item); - item = new BasketItem(inventory.GetCode("Bagel", "Sesame")); - basket.Add(item); - item = new BasketItem(inventory.GetCode("Coffee", "White")); - basket.Add(item); - item = new BasketItem(inventory.GetCode("Bagel", "Plain"), inventory.GetCode("Filling", "Bacon")); - basket.Add(item); item = new BasketItem(inventory.GetCode(name, variant)); basket.Add(item); - double expectedCost = 3.56 + cost; + + double expectedCost = 0.88 + cost; double result = basket.ShowCost(); diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index 2f7d804f..ad3fb531 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -49,22 +49,32 @@ public void TestAddToBasketWithFilling(string name, string variant, double funds } - [TestCase("Bagel", "Plain", 222.0, 2, 0.78)] - [TestCase("Fish", "Plain", 222.0, 4, 0.0)]//does not exist - [TestCase("Bagel", "Kangeroo", 222.0, 2, 0.0)] //does not exist + [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", 222.0, 7, 2.45)] //basket overfill - [TestCase("Coffee", "White", 222.0, 1, 1.19)] + [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); } - Assert.That(customer.ShowCost() == expectedCost); + // FOR EXTENSION TESTS + //_____________________________________ + customer.AddToBasket("Coffee", "Black"); + customer.AddToBasket("Coffee", "Latte"); + //________________________________ + + double cost = customer.ShowCost(); + Assert.That(cost == expectedCost); } From e279a78d4e17cc97e0f4556c2e60b0c06b220711 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 20 Aug 2024 10:07:18 +0200 Subject: [PATCH 26/31] domain updated, extension 2 --- DOMAIN.md | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index 49b28081..01456cfd 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -34,18 +34,19 @@ | |ShowCost() |Calls basket to output cost |double | | |of items in basket | | | | | -| |EXTENTION 1: Showcost |Discounts oppertunities |double +| |EXTENSION 1: Showcost |Discounts oppertunities |double | | |discovered and applied | | | | | +| |EXTENSION 2: Purchase |Calls for a manager receipt.| true +| | | Cart is not empty | +| | | Then empties cart | | | | | -| | | | -| | | | -| | | | -| | | | -| | | | -| | | | +| | |Calls for a manager receipt.| false +| | | Cart is empty | +| | | | | | | | |__________|_________________________________________|____________________________| +|Manager | | | | | | | | |ConfirmOrder(string namne, string variant| | | |, double remainingFunds, int basketSize) | | @@ -56,12 +57,16 @@ | | |Funds are insufficient for |false | | |order or item is not on menu| | | |or capacity is full | -|Manager | | | | | | | | | | | | |ChangeCapacity(int newCapacity) |NewCapacity is non-negative |true | | | | | | |NewCapacity is negative |false +| | | | +| | EXTENSION 2 | | +| | PrintReceipt(Cart cart) |Calls Receipt.PrintReceipt |------- +| | | | +| | | | |__________|_________________________________________|____________________________| |Basket | | | | | ShowCost() |Shows sum of bagels in order|double @@ -84,5 +89,23 @@ | | | | | | |Item does not exist in |-1 | | |inventory | +|__________|_________________________________________|____________________________| +|Receipt |EXTENSION2 | | +| | | | +| |PrintReceipt(Cart) |Prints receipt of items in | string +| | |cart | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | +| | | | |__________|_________________________________________|____________________________|______________________________________ - \ No newline at end of file + + + + +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 From 8a01cee0e7d9fa3718bbb3bc0f67da5920d267d2 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 20 Aug 2024 10:32:06 +0200 Subject: [PATCH 27/31] PrintReceipt test written --- DOMAIN.md | 16 +++++----- exercise.main/Customer.cs | 5 ++++ exercise.main/Receipt.cs | 12 ++++++++ exercise.tests/CustomerTest.cs | 2 ++ exercise.tests/ReceiptTest.cs | 54 ++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 exercise.main/Receipt.cs create mode 100644 exercise.tests/ReceiptTest.cs diff --git a/DOMAIN.md b/DOMAIN.md index 01456cfd..5ddd0674 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -34,15 +34,15 @@ | |ShowCost() |Calls basket to output cost |double | | |of items in basket | | | | | -| |EXTENSION 1: Showcost |Discounts oppertunities |double +| |EXTENSION 1: Showcost() |Discounts oppertunities |double | | |discovered and applied | | | | | -| |EXTENSION 2: Purchase |Calls for a manager receipt.| true -| | | Cart is not empty | -| | | Then empties cart | +| |EXTENSION 2: Purchase() |Calls for a manager receipt.| true +| | |Basket is not empty | +| | | Then empties basket | | | | | | | |Calls for a manager receipt.| false -| | | Cart is empty | +| | |Basket is empty | | | | | | | | | |__________|_________________________________________|____________________________| @@ -64,7 +64,7 @@ | | |NewCapacity is negative |false | | | | | | EXTENSION 2 | | -| | PrintReceipt(Cart cart) |Calls Receipt.PrintReceipt |------- +| | PrintReceipt(Basket basket) |Calls Receipt.PrintReceipt |------- | | | | | | | | |__________|_________________________________________|____________________________| @@ -92,8 +92,8 @@ |__________|_________________________________________|____________________________| |Receipt |EXTENSION2 | | | | | | -| |PrintReceipt(Cart) |Prints receipt of items in | string -| | |cart | +| |PrintReceipt(Basket) |Prints receipt of items in | string +| | |basket | | | | | | | | | | | | | diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index 3bac5f9b..da6d3094 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -52,6 +52,11 @@ public bool AddToBasket(string name, string variant, string filling) return false; } + public bool Purchase() + { + throw new NotImplementedException(); + } + public bool RemoveItem(string name, string variant) { return basket.RemoveFromBasket(name, variant); diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs new file mode 100644 index 00000000..229deed8 --- /dev/null +++ b/exercise.main/Receipt.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Receipt + { + } +} diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index ad3fb531..b8f62d8d 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -93,5 +93,7 @@ public void TestRemoveFromBasket(string name, string variant, bool expected) Assert.That(result == expected); } + + } } diff --git a/exercise.tests/ReceiptTest.cs b/exercise.tests/ReceiptTest.cs new file mode 100644 index 00000000..11cbd0df --- /dev/null +++ b/exercise.tests/ReceiptTest.cs @@ -0,0 +1,54 @@ +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(100000); + 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); + } + } + } +} From 765a4d8155d54e475605ec3db283bd5d73f95368 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 20 Aug 2024 12:20:06 +0200 Subject: [PATCH 28/31] Receipt done, also shows total saving. Exension 1 + a little of 2 --- DOMAIN.md | 8 ++--- exercise.main/Basket.cs | 30 +++++++++++++--- exercise.main/Customer.cs | 9 ++++- exercise.main/Manager.cs | 11 ++++++ exercise.main/Program.cs | 1 + exercise.main/Receipt.cs | 73 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+), 9 deletions(-) diff --git a/DOMAIN.md b/DOMAIN.md index 5ddd0674..90c15485 100644 --- a/DOMAIN.md +++ b/DOMAIN.md @@ -37,7 +37,7 @@ | |EXTENSION 1: Showcost() |Discounts oppertunities |double | | |discovered and applied | | | | | -| |EXTENSION 2: Purchase() |Calls for a manager receipt.| true +| |EXTENSION 2+3: Purchase() |Calls for a manager receipt.| true | | |Basket is not empty | | | | Then empties basket | | | | | @@ -63,9 +63,9 @@ | | | | | | |NewCapacity is negative |false | | | | -| | EXTENSION 2 | | +| | EXTENSION 2+3 | | | | PrintReceipt(Basket basket) |Calls Receipt.PrintReceipt |------- -| | | | +| | | | | | | | |__________|_________________________________________|____________________________| |Basket | | | @@ -90,7 +90,7 @@ | | |Item does not exist in |-1 | | |inventory | |__________|_________________________________________|____________________________| -|Receipt |EXTENSION2 | | +|Receipt |EXTENSION2+3 | | | | | | | |PrintReceipt(Basket) |Prints receipt of items in | string | | |basket | diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 9e26d9cb..ecb936ad 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -24,9 +24,11 @@ public BasketItem(string coffeeOrBagel, string filling) this.filling = filling; } } + + private double totalDiscount = 0.0; Inventory inventory = new Inventory(); - private List basket = new List(); + public List basket = new List(); public void Add(BasketItem item) { basket.Add(item); @@ -54,6 +56,7 @@ public bool OrderInBasket(string name, string variant) public double ShowCost() { + totalDiscount = 0.0; double retCost = 0.0; int bagleAmountTaste = 0; int bagleAmountPlain = 0; @@ -93,14 +96,16 @@ public double ShowCost() int discount12 = bagleAmountTaste / 12; // int should just remove the decimals int spare6Taste = spare12Taste % 6; int discount6 = spare12Taste / 6;// int should just remove the decimals + + 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 - - + + 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 @@ -117,11 +122,13 @@ public double ShowCost() { sparePlain--; retCost -= 0.13; + totalDiscount += 0.13; } else if(spare6Taste > 0) { spare6Taste--; retCost -= 0.23; + totalDiscount += 0.23; } } for (int i = 0; i < cof2; i++)//white/ @@ -130,11 +137,13 @@ public double ShowCost() { sparePlain--; retCost -= 0.33; + totalDiscount += 0.33; } else if (spare6Taste > 0) { spare6Taste--; retCost -= 0.43; + totalDiscount += 0.43; } } for (int i = 0; i < cof3; i++)// capuccino/latte @@ -143,17 +152,23 @@ public double ShowCost() { sparePlain--; retCost -= 0.43; + totalDiscount += 0.43; } else if (spare6Taste > 0) { spare6Taste--; retCost -= 0.53; + totalDiscount += 0.43; } } - + 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); @@ -182,5 +197,12 @@ public bool RemoveFromBasket(string name, string variant) } return false; } + + public void ClearBasket() + { + basket.Clear(); + } + + } } diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index da6d3094..eb74bdf6 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -52,9 +52,16 @@ public bool AddToBasket(string name, string variant, string filling) return false; } + public bool Purchase() { - throw new NotImplementedException(); + bool result = manager.PrintReceipt(basket); + if (result) + { + basket.ClearBasket(); + return true; + } + return false; } public bool RemoveItem(string name, string variant) diff --git a/exercise.main/Manager.cs b/exercise.main/Manager.cs index 29ef7fc5..200acb35 100644 --- a/exercise.main/Manager.cs +++ b/exercise.main/Manager.cs @@ -40,5 +40,16 @@ public bool ConfirmOrder(string name, string variant, double remainingFunds, int 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 52d0dfb0..a88bc21a 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,5 +1,6 @@ // 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); diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs index 229deed8..f6b3f09e 100644 --- a/exercise.main/Receipt.cs +++ b/exercise.main/Receipt.cs @@ -8,5 +8,78 @@ 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($"£{cost * item.Value}"); + } + // all products printed + + //Total £10.43 + + 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 < 22 - 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()); + } } } From 52b35d63e3805e97c0f759b6c3dea3f59ae4e285 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 20 Aug 2024 14:20:30 +0200 Subject: [PATCH 29/31] All extensions tested and done --- exercise.main/Basket.cs | 66 ++++++++++++++++++++++++++++++++--- exercise.main/Customer.cs | 2 +- exercise.main/Receipt.cs | 27 +++++++++++--- exercise.tests/ReceiptTest.cs | 5 ++- 4 files changed, 88 insertions(+), 12 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index ecb936ad..c791cb43 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -9,6 +9,18 @@ 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; @@ -26,6 +38,7 @@ public BasketItem(string coffeeOrBagel, string filling) } private double totalDiscount = 0.0; + public Dictionary discounts = new Dictionary(); Inventory inventory = new Inventory(); public List basket = new List(); @@ -65,6 +78,11 @@ public double ShowCost() 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) { @@ -84,10 +102,14 @@ public double ShowCost() { cof2++; // middle } - else if (item.coffeeOrBagel == "COFC" || item.coffeeOrBagel == "COFL") + 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); } @@ -97,6 +119,7 @@ public double ShowCost() 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; @@ -104,6 +127,7 @@ public double ShowCost() //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; @@ -118,17 +142,19 @@ public double ShowCost() for(int i = 0; i < cof1; i++) //black { - if(sparePlain > 0) + if (sparePlain > 0) { sparePlain--; retCost -= 0.13; totalDiscount += 0.13; + discounts["COFB"] += 0.13; } - else if(spare6Taste > 0) + else if (spare6Taste > 0) { spare6Taste--; retCost -= 0.23; totalDiscount += 0.23; + discounts["COFB"] += 0.23; } } for (int i = 0; i < cof2; i++)//white/ @@ -138,30 +164,60 @@ public double ShowCost() 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/latte + 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); } diff --git a/exercise.main/Customer.cs b/exercise.main/Customer.cs index eb74bdf6..a1ed3b96 100644 --- a/exercise.main/Customer.cs +++ b/exercise.main/Customer.cs @@ -17,7 +17,7 @@ public Customer(double funds) this.funds = funds; if(funds == 2222.0) { - manager.ChangeCapcity(200); // this is for extension tests + manager.ChangeCapcity(400); // this is for extension tests } } diff --git a/exercise.main/Receipt.cs b/exercise.main/Receipt.cs index f6b3f09e..63eae617 100644 --- a/exercise.main/Receipt.cs +++ b/exercise.main/Receipt.cs @@ -59,18 +59,35 @@ public void PrintReceipt(Basket basket) { receipt.Append(" "); } - receipt.AppendLine($"£{cost * item.Value}"); - } - // all products printed + receipt.AppendLine($"£{Math.Round(cost * item.Value, 2)}"); - //Total £10.43 + //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 < 22 - costTotal.ToString().Length; i++) + for (int i = 0; i < 23 - costTotal.ToString().Length; i++) { receipt.Append(" "); } diff --git a/exercise.tests/ReceiptTest.cs b/exercise.tests/ReceiptTest.cs index 11cbd0df..1a9e1ef0 100644 --- a/exercise.tests/ReceiptTest.cs +++ b/exercise.tests/ReceiptTest.cs @@ -19,8 +19,11 @@ public class ReceiptTest [TestCase(15, 33, false)] public void TestPrintReceipt(int buyBagel, int buyCoffee, bool filling) { - Customer customer = new Customer(100000); + Customer customer = new Customer(2222.0); Basket basket = new Basket(); + + + for(int i = 0; i < buyBagel; i++) { customer.AddToBasket("Bagel", "Onion"); From c16045d04f71698976f73bac3090d5b5eb644281 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 20 Aug 2024 14:21:03 +0200 Subject: [PATCH 30/31] Ignore previous commit message, extensions 1-3 are done --- exercise.tests/CustomerTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercise.tests/CustomerTest.cs b/exercise.tests/CustomerTest.cs index b8f62d8d..e3481ed0 100644 --- a/exercise.tests/CustomerTest.cs +++ b/exercise.tests/CustomerTest.cs @@ -27,7 +27,7 @@ public void TestAddToBasket(string name, string variant, double funds,bool[] exp Assert.That(result == expected[i]); } } - + [TestCase("Bagel", "Plain", 2.0, "Bacon", new bool[] { true, true })] From 1956c04a783bf02615142aa269dd0c587813315c Mon Sep 17 00:00:00 2001 From: Felix Date: Fri, 23 Aug 2024 10:30:58 +0200 Subject: [PATCH 31/31] added class diagram --- exercise.main/ClassDiagram1.cd | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 exercise.main/ClassDiagram1.cd 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