From 64cf93646a4f1aa03aadc4d3643e5de655502868 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 11:14:33 +0200 Subject: [PATCH 01/28] Stian Forren --- exercise.main/domailModel.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 exercise.main/domailModel.md diff --git a/exercise.main/domailModel.md b/exercise.main/domailModel.md new file mode 100644 index 00000000..58fdf91b --- /dev/null +++ b/exercise.main/domailModel.md @@ -0,0 +1,11 @@ +|Classes| Methods/Properties|Scenario|Output| +|-------|-------------------|---------|------| +|Basket.cs|Add(IProduct)|Want to add a specific bagel to basket|Adds the bagel to the basket| +|Basket.cs|Remove(int id)| id like the ability to remove a bagel from basket| removes the given bagel from basket| +|Basket.cs|IsFull()| want feedback if basket is full| returnes true if full, false otherwise| +|BagelShop.cs|changeCapacity(int capacity)| want the ability to change basket size| basket size changed to wanted size| +|Basket.cs|isPresent(int id)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| +|Basket.cs|GetTotalCost()| want to see total cost| returns the total cost of the basket| +|Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| +|Inventory.cs|getFillingCost()| want to see price of fillings| returns list of fillings with price| +|Inventory.cs|inInventory(IProduct product)|only want to sell items in inventory|returns true if item in inventory, false otherwise| From f9243446c6d67512a7d34d58a274428f09673ed8 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 11:15:53 +0200 Subject: [PATCH 02/28] Stian Forren --- exercise.main/{domailModel.md => domainModel.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename exercise.main/{domailModel.md => domainModel.md} (100%) diff --git a/exercise.main/domailModel.md b/exercise.main/domainModel.md similarity index 100% rename from exercise.main/domailModel.md rename to exercise.main/domainModel.md From 765e227211d0c6ca5aac79e93a8643d7d508edec Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 11:35:05 +0200 Subject: [PATCH 03/28] Stian Forren --- exercise.main/Bagel.cs | 13 +++++++++++++ exercise.main/BagelShop.cs | 12 ++++++++++++ exercise.main/Basket.cs | 26 ++++++++++++++++++++++++++ exercise.main/IProduct.cs | 13 +++++++++++++ exercise.tests/CoreTest.cs | 25 +++++++++++++++++++++++++ exercise.tests/exercise.tests.csproj | 6 +++++- 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 exercise.main/Bagel.cs create mode 100644 exercise.main/BagelShop.cs create mode 100644 exercise.main/Basket.cs create mode 100644 exercise.main/IProduct.cs create mode 100644 exercise.tests/CoreTest.cs diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs new file mode 100644 index 00000000..6900ac89 --- /dev/null +++ b/exercise.main/Bagel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Bagel : IProduct + { + + } +} diff --git a/exercise.main/BagelShop.cs b/exercise.main/BagelShop.cs new file mode 100644 index 00000000..ee568721 --- /dev/null +++ b/exercise.main/BagelShop.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 BagelShop + { + } +} diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs new file mode 100644 index 00000000..32cea01c --- /dev/null +++ b/exercise.main/Basket.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Basket + { + + private int _basketSize; + public List ProductList { get; set; } + + public Basket(int basketSize) + { + _basketSize = basketSize; + } + + + public void Add(IProduct product) + { + + } + } +} diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs new file mode 100644 index 00000000..4923e5c2 --- /dev/null +++ b/exercise.main/IProduct.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public interface IProduct + { + + } +} diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs new file mode 100644 index 00000000..1a99786e --- /dev/null +++ b/exercise.tests/CoreTest.cs @@ -0,0 +1,25 @@ +using exercise.main; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.tests +{ + [TestFixture] + public class CoreTest + { + [Test] + public void TestAdd() + { + Basket basket = new Basket(3); + IProduct bagel = new Bagel(); + basket.Add(bagel); + + Assert.That(basket.ProductList.Count == 1); + + + } + } +} diff --git a/exercise.tests/exercise.tests.csproj b/exercise.tests/exercise.tests.csproj index 9fed8e17..42492291 100644 --- a/exercise.tests/exercise.tests.csproj +++ b/exercise.tests/exercise.tests.csproj @@ -1,4 +1,4 @@ - + net9.0 @@ -17,4 +17,8 @@ + + + + From a4c96512c877d7055387b0efc129683febffd674 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 11:56:55 +0200 Subject: [PATCH 04/28] Stian Forren --- exercise.main/Bagel.cs | 3 ++- exercise.main/Basket.cs | 5 ++--- exercise.main/IProduct.cs | 1 - exercise.tests/CoreTest.cs | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 6900ac89..efe9b2c2 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -6,8 +6,9 @@ namespace exercise.main { + public class Bagel : IProduct { - + } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 32cea01c..472eed17 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -10,17 +10,16 @@ public class Basket { private int _basketSize; - public List ProductList { get; set; } + public List ProductList = new List(); public Basket(int basketSize) { _basketSize = basketSize; } - public void Add(IProduct product) { - + ProductList.Add(product); } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 4923e5c2..c4208b63 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -8,6 +8,5 @@ namespace exercise.main { public interface IProduct { - } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 1a99786e..96ff13d2 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -14,7 +14,7 @@ public class CoreTest public void TestAdd() { Basket basket = new Basket(3); - IProduct bagel = new Bagel(); + Bagel bagel = new Bagel(); basket.Add(bagel); Assert.That(basket.ProductList.Count == 1); From 1fb37f218cdc2e164506794c68b6dcbbb52dc3fa Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 12:00:55 +0200 Subject: [PATCH 05/28] Stian Forren --- exercise.main/Bagel.cs | 4 +++- exercise.main/Basket.cs | 5 +++++ exercise.main/IProduct.cs | 1 + exercise.tests/CoreTest.cs | 11 +++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index efe9b2c2..c9772cd0 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata.Ecma335; using System.Text; using System.Threading.Tasks; @@ -9,6 +10,7 @@ namespace exercise.main public class Bagel : IProduct { - + private int _id; + public int Id { get { return _id; } set { _id = value; } } } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 472eed17..a6d27bae 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -21,5 +21,10 @@ public void Add(IProduct product) { ProductList.Add(product); } + + public void Remove(int v) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index c4208b63..615f5462 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -8,5 +8,6 @@ namespace exercise.main { public interface IProduct { + int Id { get; set; } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 96ff13d2..7ae9f5c0 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -18,7 +18,18 @@ public void TestAdd() basket.Add(bagel); Assert.That(basket.ProductList.Count == 1); + } + + [Test] + public void TestRemove() + { + Basket basket = new Basket(3); + Bagel bagel = new Bagel(); + basket.Add(bagel); + + basket.Remove(0); + Assert.That(basket.ProductList.Count == 0); } } From 1ec8301722bcb984b5c55ee3f1dca86acd8ecae7 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 12:01:35 +0200 Subject: [PATCH 06/28] Stian Forren --- exercise.main/Basket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index a6d27bae..32aa70e1 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -22,9 +22,9 @@ public void Add(IProduct product) ProductList.Add(product); } - public void Remove(int v) + public void Remove(int id) { - throw new NotImplementedException(); + ProductList.RemoveAt(id); } } } From 0cbc9a9954b0024cd6240eb673fea560359650d6 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 12:04:28 +0200 Subject: [PATCH 07/28] Stian Forren --- exercise.main/Basket.cs | 5 +++++ exercise.tests/CoreTest.cs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 32aa70e1..5bfaea28 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -26,5 +26,10 @@ public void Remove(int id) { ProductList.RemoveAt(id); } + + public bool IsFull() + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 7ae9f5c0..1002ba5b 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -30,6 +30,21 @@ public void TestRemove() basket.Remove(0); Assert.That(basket.ProductList.Count == 0); + } + + [Test] + public void TestIsFull() + { + Basket basket = new Basket(3); + Bagel bagel = new Bagel(); + Bagel bagel2 = new Bagel(); + Bagel bagel3 = new Bagel(); + + basket.Add(bagel); + Assert.IsFalse(basket.IsFull()); + basket.Add(bagel2); + basket.Add(bagel3); + Assert.IsTrue(basket.IsFull()); } } From c0aa06938f053066d517e5f23e3bf8a78a882ab7 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 12:06:07 +0200 Subject: [PATCH 08/28] Stian Forren --- exercise.main/Basket.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 5bfaea28..1d58d7fe 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -29,7 +29,7 @@ public void Remove(int id) public bool IsFull() { - throw new NotImplementedException(); + return ProductList.Count < _basketSize ? false : true; } } } From 0371ea6a354fb2739e44b950ffb6d63c6bc29ef0 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 12:47:17 +0200 Subject: [PATCH 09/28] Stian Forren --- exercise.main/BagelShop.cs | 4 +++- exercise.main/Basket.cs | 2 ++ exercise.main/domainModel.md | 2 +- exercise.tests/CoreTest.cs | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/exercise.main/BagelShop.cs b/exercise.main/BagelShop.cs index ee568721..2853f073 100644 --- a/exercise.main/BagelShop.cs +++ b/exercise.main/BagelShop.cs @@ -6,7 +6,9 @@ namespace exercise.main { - internal class BagelShop + public class BagelShop { + public int _basketSize { get; set; } + } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 1d58d7fe..d05295f0 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -31,5 +31,7 @@ public bool IsFull() { return ProductList.Count < _basketSize ? false : true; } + + public int BasketSize { get { return _basketSize; } set { _basketSize = value; } } } } diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md index 58fdf91b..30d1e72a 100644 --- a/exercise.main/domainModel.md +++ b/exercise.main/domainModel.md @@ -3,7 +3,7 @@ |Basket.cs|Add(IProduct)|Want to add a specific bagel to basket|Adds the bagel to the basket| |Basket.cs|Remove(int id)| id like the ability to remove a bagel from basket| removes the given bagel from basket| |Basket.cs|IsFull()| want feedback if basket is full| returnes true if full, false otherwise| -|BagelShop.cs|changeCapacity(int capacity)| want the ability to change basket size| basket size changed to wanted size| +|Basket.cs|BasketSize| want the ability to change basket size| basket size changed to wanted size| |Basket.cs|isPresent(int id)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| |Basket.cs|GetTotalCost()| want to see total cost| returns the total cost of the basket| |Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 1002ba5b..a4ef076d 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -47,5 +47,14 @@ public void TestIsFull() Assert.IsTrue(basket.IsFull()); } + + [Test] + public void TestBasketSize() + { + Basket basket = new Basket(3); + Assert.That(basket.BasketSize == 3); + basket.BasketSize = 6; + Assert.That(basket.BasketSize == 6); + } } } From 07f1ea916106fd09b2b204a29d237f358f086c21 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 13:07:18 +0200 Subject: [PATCH 10/28] Stian Forren --- exercise.main/Bagel.cs | 9 +++++++-- exercise.main/Basket.cs | 6 ++++++ exercise.main/IProduct.cs | 2 +- exercise.main/Inventory.cs | 24 ++++++++++++++++++++++++ exercise.main/domainModel.md | 2 +- exercise.tests/CoreTest.cs | 7 +++++++ 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 exercise.main/Inventory.cs diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index c9772cd0..5d9bec32 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -10,7 +10,12 @@ namespace exercise.main public class Bagel : IProduct { - private int _id; - public int Id { get { return _id; } set { _id = value; } } + private int _SKU_ID; + public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } + + public Bagel(string name) + { + + } } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index d05295f0..4a594277 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -11,6 +11,7 @@ public class Basket private int _basketSize; public List ProductList = new List(); + private Inventory inventory = new Inventory(); public Basket(int basketSize) { @@ -33,5 +34,10 @@ public bool IsFull() } public int BasketSize { get { return _basketSize; } set { _basketSize = value; } } + + public bool ItemInBasket(int sku_id) + { + return ProductList.Any(x => x.SKU_ID == sku_id); + } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 615f5462..ea38f233 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -8,6 +8,6 @@ namespace exercise.main { public interface IProduct { - int Id { get; set; } + int SKU_ID { get; set; } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs new file mode 100644 index 00000000..1b609715 --- /dev/null +++ b/exercise.main/Inventory.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class Inventory + { + public Dictionary toSkuId = new Dictionary(); + + + public Inventory() + { + toSkuId.Add("BGLO", 0); + toSkuId.Add("BGLP", 1); + toSkuId.Add("BGLE", 2); + toSkuId.Add("BGLS", 3); + } + + + } +} diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md index 30d1e72a..b4461706 100644 --- a/exercise.main/domainModel.md +++ b/exercise.main/domainModel.md @@ -4,7 +4,7 @@ |Basket.cs|Remove(int id)| id like the ability to remove a bagel from basket| removes the given bagel from basket| |Basket.cs|IsFull()| want feedback if basket is full| returnes true if full, false otherwise| |Basket.cs|BasketSize| want the ability to change basket size| basket size changed to wanted size| -|Basket.cs|isPresent(int id)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| +|Basket.cs|isPresent(int SKU_ID)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| |Basket.cs|GetTotalCost()| want to see total cost| returns the total cost of the basket| |Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| |Inventory.cs|getFillingCost()| want to see price of fillings| returns list of fillings with price| diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index a4ef076d..2e8634d8 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -56,5 +56,12 @@ public void TestBasketSize() basket.BasketSize = 6; Assert.That(basket.BasketSize == 6); } + + [Test] + public void TestItemInBasket() + { + Basket basket = new Basket(3); + Bagel bagel = new Bagel(); + } } } From 67bf628c044d0fbc7543ba157b5dccdfbee1710e Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 13:14:10 +0200 Subject: [PATCH 11/28] Stian Forren --- exercise.main/Bagel.cs | 6 ++++-- exercise.main/Basket.cs | 4 ++-- exercise.main/IProduct.cs | 1 + exercise.tests/CoreTest.cs | 15 +++++++++------ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/exercise.main/Bagel.cs b/exercise.main/Bagel.cs index 5d9bec32..0653fabc 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Bagel.cs @@ -11,11 +11,13 @@ namespace exercise.main public class Bagel : IProduct { private int _SKU_ID; - public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } + private string _NAME; public Bagel(string name) { - + _NAME = name; } + public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } + public string Name { get { return _NAME; } set { _NAME = value; } } } } diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 4a594277..3c24ba53 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -35,9 +35,9 @@ public bool IsFull() public int BasketSize { get { return _basketSize; } set { _basketSize = value; } } - public bool ItemInBasket(int sku_id) + public bool ItemInBasket(string type) { - return ProductList.Any(x => x.SKU_ID == sku_id); + return ProductList.Any(x => x.Name == type); } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index ea38f233..240316b2 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -9,5 +9,6 @@ namespace exercise.main public interface IProduct { int SKU_ID { get; set; } + string Name { get; set; } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 2e8634d8..13f89b9a 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -14,7 +14,7 @@ public class CoreTest public void TestAdd() { Basket basket = new Basket(3); - Bagel bagel = new Bagel(); + Bagel bagel = new Bagel("BGLO"); basket.Add(bagel); Assert.That(basket.ProductList.Count == 1); @@ -24,7 +24,7 @@ public void TestAdd() public void TestRemove() { Basket basket = new Basket(3); - Bagel bagel = new Bagel(); + Bagel bagel = new Bagel("BGLO"); basket.Add(bagel); basket.Remove(0); @@ -36,9 +36,9 @@ public void TestRemove() public void TestIsFull() { Basket basket = new Basket(3); - Bagel bagel = new Bagel(); - Bagel bagel2 = new Bagel(); - Bagel bagel3 = new Bagel(); + Bagel bagel = new Bagel("BGLO"); + Bagel bagel2 = new Bagel("BGLO"); + Bagel bagel3 = new Bagel("BGLO"); basket.Add(bagel); Assert.IsFalse(basket.IsFull()); @@ -61,7 +61,10 @@ public void TestBasketSize() public void TestItemInBasket() { Basket basket = new Basket(3); - Bagel bagel = new Bagel(); + Bagel bagel = new Bagel("BGLO"); + basket.Add(bagel); + + Assert.IsTrue(basket.ItemInBasket("BGLO")); } } } From 327e5b3d5f5b7b34d43cb9177f21aa154969a67e Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 13:59:56 +0200 Subject: [PATCH 12/28] Stian Forren --- exercise.main/Basket.cs | 7 ++++++- exercise.main/IProduct.cs | 4 +++- exercise.main/InvItem.cs | 26 ++++++++++++++++++++++++++ exercise.main/Inventory.cs | 12 +++++------- exercise.main/{ => Products}/Bagel.cs | 6 ++++-- exercise.main/domainModel.md | 1 + exercise.tests/CoreTest.cs | 10 ++++++++++ 7 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 exercise.main/InvItem.cs rename exercise.main/{ => Products}/Bagel.cs (69%) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 3c24ba53..7b561f72 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -37,7 +37,12 @@ public bool IsFull() public bool ItemInBasket(string type) { - return ProductList.Any(x => x.Name == type); + return ProductList.Any(x => x.SKU_NAME == type); + } + + public float getBagelCost(string v) + { + throw new NotImplementedException(); } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 240316b2..e766a601 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -9,6 +9,8 @@ namespace exercise.main public interface IProduct { int SKU_ID { get; set; } - string Name { get; set; } + string SKU_NAME { get; set; } + + float cost { get; } } } diff --git a/exercise.main/InvItem.cs b/exercise.main/InvItem.cs new file mode 100644 index 00000000..238949f9 --- /dev/null +++ b/exercise.main/InvItem.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public class InvItem + { + private int _id; + private float _price; + + public InvItem(int setId, float setPrice) + { + _price = setPrice; + _id = setId; + } + + public int ID { get { return _id; } } + public float Price { get { return _price; } + + + + } +}} diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 1b609715..0acafdfb 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -8,17 +8,15 @@ namespace exercise.main { public class Inventory { - public Dictionary toSkuId = new Dictionary(); + public Dictionary inventory = new Dictionary(); public Inventory() { - toSkuId.Add("BGLO", 0); - toSkuId.Add("BGLP", 1); - toSkuId.Add("BGLE", 2); - toSkuId.Add("BGLS", 3); + inventory.Add("BGLO", new InvItem(0, 0.49f)); + inventory.Add("BGLP", new InvItem(1, 0.39f)); + inventory.Add("BGLE", new InvItem(2, 0.49f)); + inventory.Add("BGLS", new InvItem(3, 0.49f)); } - - } } diff --git a/exercise.main/Bagel.cs b/exercise.main/Products/Bagel.cs similarity index 69% rename from exercise.main/Bagel.cs rename to exercise.main/Products/Bagel.cs index 0653fabc..b936a56d 100644 --- a/exercise.main/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; -namespace exercise.main +namespace exercise.main.Products { public class Bagel : IProduct @@ -18,6 +18,8 @@ public Bagel(string name) _NAME = name; } public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } - public string Name { get { return _NAME; } set { _NAME = value; } } + public string SKU_NAME { get { return _NAME; } set { _NAME = value; } } + + public float cost { get => throw new NotImplementedException();} } } diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md index b4461706..3c106f42 100644 --- a/exercise.main/domainModel.md +++ b/exercise.main/domainModel.md @@ -5,6 +5,7 @@ |Basket.cs|IsFull()| want feedback if basket is full| returnes true if full, false otherwise| |Basket.cs|BasketSize| want the ability to change basket size| basket size changed to wanted size| |Basket.cs|isPresent(int SKU_ID)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| +|Basket.cs|GetBagelCost(string name)| want to see the cost of a bagel| returns the price of given bagel| |Basket.cs|GetTotalCost()| want to see total cost| returns the total cost of the basket| |Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| |Inventory.cs|getFillingCost()| want to see price of fillings| returns list of fillings with price| diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 13f89b9a..b7069b6d 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -1,4 +1,5 @@ using exercise.main; +using exercise.main.Products; using System; using System.Collections.Generic; using System.Linq; @@ -66,5 +67,14 @@ public void TestItemInBasket() Assert.IsTrue(basket.ItemInBasket("BGLO")); } + + [Test] + public void TestGetBagelCost() + { + Basket basket = new Basket(3); + Bagel bagel = new Bagel("BGLO"); + + Assert.That(basket.getBagelCost("BGLO") == 0.49f); + } } } From 487e24ed8b7a0890b8a8fffa4c775309dafb267e Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:01:18 +0200 Subject: [PATCH 13/28] Stian Forren --- exercise.main/Basket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 7b561f72..677053da 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -40,9 +40,9 @@ public bool ItemInBasket(string type) return ProductList.Any(x => x.SKU_NAME == type); } - public float getBagelCost(string v) + public float getBagelCost(string bagelSKU) { - throw new NotImplementedException(); + return inventory.inventory[bagelSKU].Price; } } } From 2b1b6af1d2e0eaf3aa6ca906e44de152ddf6e3d7 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:37:30 +0200 Subject: [PATCH 14/28] Stian Forren --- exercise.main/Basket.cs | 12 +++++-- exercise.main/IProduct.cs | 2 +- exercise.main/Products/Bagel.cs | 13 +++++-- exercise.main/Products/Filling.cs | 15 ++++++++ exercise.tests/CoreTest.cs | 60 ++++++++++++++++++++++++------- 5 files changed, 83 insertions(+), 19 deletions(-) create mode 100644 exercise.main/Products/Filling.cs diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 677053da..16aa1a92 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -11,10 +11,11 @@ public class Basket private int _basketSize; public List ProductList = new List(); - private Inventory inventory = new Inventory(); + private Inventory _inventory; - public Basket(int basketSize) + public Basket(int basketSize, Inventory inventory) { + _inventory = inventory; _basketSize = basketSize; } @@ -42,7 +43,12 @@ public bool ItemInBasket(string type) public float getBagelCost(string bagelSKU) { - return inventory.inventory[bagelSKU].Price; + return _inventory.inventory[bagelSKU].Price; + } + + public float getTotalCost() + { + return ProductList.Sum(x => x.Price); } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index e766a601..37239750 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -11,6 +11,6 @@ public interface IProduct int SKU_ID { get; set; } string SKU_NAME { get; set; } - float cost { get; } + float Price { get; set; } } } diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs index b936a56d..cd44602d 100644 --- a/exercise.main/Products/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -12,14 +12,23 @@ public class Bagel : IProduct { private int _SKU_ID; private string _NAME; + private List fillings; + private float _cost; - public Bagel(string name) + public Bagel(string name, Inventory inventory) { _NAME = name; + fillings = new List(); + _cost = inventory.inventory[name].Price; } public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } public string SKU_NAME { get { return _NAME; } set { _NAME = value; } } + public float Price { get { return _cost; } set { _cost = value; } } + public List Fillings { get { return fillings; } } - public float cost { get => throw new NotImplementedException();} + public void addFilling(string v) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs new file mode 100644 index 00000000..cae0566b --- /dev/null +++ b/exercise.main/Products/Filling.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Products +{ + public class Filling : IProduct + { + public int SKU_ID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public float Price { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + } +} diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index b7069b6d..f9141c37 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -14,8 +14,9 @@ public class CoreTest [Test] public void TestAdd() { - Basket basket = new Basket(3); - Bagel bagel = new Bagel("BGLO"); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3,inventory); + Bagel bagel = new Bagel("BGLO", inventory); basket.Add(bagel); Assert.That(basket.ProductList.Count == 1); @@ -24,8 +25,9 @@ public void TestAdd() [Test] public void TestRemove() { - Basket basket = new Basket(3); - Bagel bagel = new Bagel("BGLO"); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); basket.Add(bagel); basket.Remove(0); @@ -36,10 +38,11 @@ public void TestRemove() [Test] public void TestIsFull() { - Basket basket = new Basket(3); - Bagel bagel = new Bagel("BGLO"); - Bagel bagel2 = new Bagel("BGLO"); - Bagel bagel3 = new Bagel("BGLO"); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO",inventory); + Bagel bagel2 = new Bagel("BGLO",inventory); + Bagel bagel3 = new Bagel("BGLO",inventory); basket.Add(bagel); Assert.IsFalse(basket.IsFull()); @@ -52,7 +55,8 @@ public void TestIsFull() [Test] public void TestBasketSize() { - Basket basket = new Basket(3); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); Assert.That(basket.BasketSize == 3); basket.BasketSize = 6; Assert.That(basket.BasketSize == 6); @@ -61,8 +65,9 @@ public void TestBasketSize() [Test] public void TestItemInBasket() { - Basket basket = new Basket(3); - Bagel bagel = new Bagel("BGLO"); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); basket.Add(bagel); Assert.IsTrue(basket.ItemInBasket("BGLO")); @@ -71,10 +76,39 @@ public void TestItemInBasket() [Test] public void TestGetBagelCost() { - Basket basket = new Basket(3); - Bagel bagel = new Bagel("BGLO"); + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); Assert.That(basket.getBagelCost("BGLO") == 0.49f); } + + [Test] + public void TestGetTotal() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + + basket.Add(bagel); + basket.Add(bagel2); + + Assert.That(basket.getTotalCost() == 0.98f); + } + + [Test] + public void TestAddFilling() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + bagel.addFilling("Cheese"); + bagel.addFilling("Egg"); + Assert.That(bagel.Fillings.Count == 2); + + } + + } } From 42708ddc1fded8114c96e128248ee45183a724a4 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:39:51 +0200 Subject: [PATCH 15/28] Stian Forren --- exercise.main/Products/Bagel.cs | 4 ++-- exercise.main/Products/Filling.cs | 7 +++++++ exercise.tests/CoreTest.cs | 4 ++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs index cd44602d..5040ca56 100644 --- a/exercise.main/Products/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -26,9 +26,9 @@ public Bagel(string name, Inventory inventory) public float Price { get { return _cost; } set { _cost = value; } } public List Fillings { get { return fillings; } } - public void addFilling(string v) + public void addFilling(Filling filling) { - throw new NotImplementedException(); + fillings.Add(filling); } } } diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs index cae0566b..a46fe0e2 100644 --- a/exercise.main/Products/Filling.cs +++ b/exercise.main/Products/Filling.cs @@ -8,6 +8,13 @@ namespace exercise.main.Products { public class Filling : IProduct { + private string _name; + private float _cost; + + public Filling(string name) + { + _name = name; + } public int SKU_ID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public float Price { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index f9141c37..1acde309 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -103,8 +103,8 @@ public void TestAddFilling() Inventory inventory = new Inventory(); Basket basket = new Basket(3, inventory); Bagel bagel = new Bagel("BGLO", inventory); - bagel.addFilling("Cheese"); - bagel.addFilling("Egg"); + bagel.addFilling(new Filling("Cheese")); + bagel.addFilling(new Filling("Egg")); Assert.That(bagel.Fillings.Count == 2); } From 88c1b4ea092090c6f0194757f26658131a602b8d Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:50:20 +0200 Subject: [PATCH 16/28] Stian Forren --- exercise.main/Basket.cs | 5 +++++ exercise.main/Inventory.cs | 7 +++++++ exercise.main/Products/Filling.cs | 6 +++--- exercise.tests/CoreTest.cs | 14 +++++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 16aa1a92..4488322d 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -50,5 +50,10 @@ public float getTotalCost() { return ProductList.Sum(x => x.Price); } + + public float getFillingCost(string fillingSKU) + { + return _inventory.inventory[fillingSKU].Price; + } } } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 0acafdfb..58daf3ef 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -17,6 +17,13 @@ public Inventory() inventory.Add("BGLP", new InvItem(1, 0.39f)); inventory.Add("BGLE", new InvItem(2, 0.49f)); inventory.Add("BGLS", new InvItem(3, 0.49f)); + inventory.Add("FILB", new InvItem(4, 0.12f)); + inventory.Add("FILE", new InvItem(5, 0.12f)); + inventory.Add("FILC", new InvItem(6, 0.12f)); + inventory.Add("FILX", new InvItem(7, 0.12f)); + inventory.Add("FILS", new InvItem(8, 0.12f)); + inventory.Add("FILH", new InvItem(9, 0.12f)); + } } } diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs index a46fe0e2..05233e26 100644 --- a/exercise.main/Products/Filling.cs +++ b/exercise.main/Products/Filling.cs @@ -11,12 +11,12 @@ public class Filling : IProduct private string _name; private float _cost; - public Filling(string name) - { + public Filling(string name, Inventory inventory) { _name = name; + _cost = inventory.inventory[name].Price; } public int SKU_ID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } - public float Price { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public float Price { get { return _cost; } set => new NotImplementedException(); } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 1acde309..51f71802 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -78,7 +78,7 @@ public void TestGetBagelCost() { Inventory inventory = new Inventory(); Basket basket = new Basket(3, inventory); - Bagel bagel = new Bagel("BGLO", inventory); + //Bagel bagel = new Bagel("BGLO", inventory); Assert.That(basket.getBagelCost("BGLO") == 0.49f); } @@ -103,10 +103,18 @@ public void TestAddFilling() Inventory inventory = new Inventory(); Basket basket = new Basket(3, inventory); Bagel bagel = new Bagel("BGLO", inventory); - bagel.addFilling(new Filling("Cheese")); - bagel.addFilling(new Filling("Egg")); + bagel.addFilling(new Filling("FILE", inventory)); + bagel.addFilling(new Filling("FILB", inventory)); Assert.That(bagel.Fillings.Count == 2); + } + + [Test] + public void TestGetCostOfFilling() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Assert.That(basket.getFillingCost("FILE") == 0.12f); } From 6a4f65549b256b88831c28bb93ff562b9a417a75 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:55:05 +0200 Subject: [PATCH 17/28] Stian Forren --- exercise.main/Basket.cs | 5 +++++ exercise.tests/CoreTest.cs | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 4488322d..e2115257 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -55,5 +55,10 @@ public float getFillingCost(string fillingSKU) { return _inventory.inventory[fillingSKU].Price; } + + public bool? inInventory(string v) + { + throw new NotImplementedException(); + } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 51f71802..f65eac18 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -117,6 +117,16 @@ public void TestGetCostOfFilling() Assert.That(basket.getFillingCost("FILE") == 0.12f); } + [Test] + public void TestInInventory() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + + Assert.IsTrue(basket.inInventory("BGLO")); + Assert.IsFalse(basket.inInventory("egg")); + } + } } From bf7b2dbd94ebad7f09ab158cb68edc706efd8dab Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 14:58:27 +0200 Subject: [PATCH 18/28] Stian Forren --- exercise.main/Basket.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index e2115257..97c8a7a6 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -56,9 +56,9 @@ public float getFillingCost(string fillingSKU) return _inventory.inventory[fillingSKU].Price; } - public bool? inInventory(string v) + public bool inInventory(string item) { - throw new NotImplementedException(); + return _inventory.inventory.ContainsKey(item); } } } From 8f87b852a8d031059ab39739e68ee33560e475e3 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 15:24:36 +0200 Subject: [PATCH 19/28] Stian Forren --- exercise.main/Basket.cs | 8 ++++---- exercise.main/IProduct.cs | 1 - exercise.main/Inventory.cs | 10 ++++++++++ exercise.main/Products/Bagel.cs | 2 -- exercise.main/Products/Filling.cs | 4 ++-- exercise.main/domainModel.md | 10 +++++----- exercise.tests/CoreTest.cs | 7 +++---- 7 files changed, 24 insertions(+), 18 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 97c8a7a6..318c56a1 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -24,9 +24,9 @@ public void Add(IProduct product) ProductList.Add(product); } - public void Remove(int id) + public void Remove(int placeInList) { - ProductList.RemoveAt(id); + ProductList.RemoveAt(placeInList); } public bool IsFull() @@ -53,12 +53,12 @@ public float getTotalCost() public float getFillingCost(string fillingSKU) { - return _inventory.inventory[fillingSKU].Price; + return _inventory.getFillingCost(fillingSKU); } public bool inInventory(string item) { - return _inventory.inventory.ContainsKey(item); + return _inventory.inInventory(item); } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 37239750..d8a4b1ed 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -8,7 +8,6 @@ namespace exercise.main { public interface IProduct { - int SKU_ID { get; set; } string SKU_NAME { get; set; } float Price { get; set; } diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 58daf3ef..34a3d062 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -25,5 +25,15 @@ public Inventory() inventory.Add("FILH", new InvItem(9, 0.12f)); } + + public float getFillingCost(string fillingSKU ) + { + return inventory[fillingSKU].Price; + } + + public bool inInventory(string SKU) + { + return inventory.ContainsKey(SKU); + } } } diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs index 5040ca56..d6503554 100644 --- a/exercise.main/Products/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -10,7 +10,6 @@ namespace exercise.main.Products public class Bagel : IProduct { - private int _SKU_ID; private string _NAME; private List fillings; private float _cost; @@ -21,7 +20,6 @@ public Bagel(string name, Inventory inventory) fillings = new List(); _cost = inventory.inventory[name].Price; } - public int SKU_ID { get { return _SKU_ID; } set { _SKU_ID = value; } } public string SKU_NAME { get { return _NAME; } set { _NAME = value; } } public float Price { get { return _cost; } set { _cost = value; } } public List Fillings { get { return fillings; } } diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs index 05233e26..a4fcd821 100644 --- a/exercise.main/Products/Filling.cs +++ b/exercise.main/Products/Filling.cs @@ -11,11 +11,11 @@ public class Filling : IProduct private string _name; private float _cost; - public Filling(string name, Inventory inventory) { + public Filling(string name, Inventory inventory) + { _name = name; _cost = inventory.inventory[name].Price; } - public int SKU_ID { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public float Price { get { return _cost; } set => new NotImplementedException(); } } diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md index 3c106f42..f367e0fb 100644 --- a/exercise.main/domainModel.md +++ b/exercise.main/domainModel.md @@ -1,12 +1,12 @@ |Classes| Methods/Properties|Scenario|Output| |-------|-------------------|---------|------| |Basket.cs|Add(IProduct)|Want to add a specific bagel to basket|Adds the bagel to the basket| -|Basket.cs|Remove(int id)| id like the ability to remove a bagel from basket| removes the given bagel from basket| +|Basket.cs|Remove(int placeinlist)| id like the ability to remove a bagel from basket| removes the given bagel from basket| |Basket.cs|IsFull()| want feedback if basket is full| returnes true if full, false otherwise| |Basket.cs|BasketSize| want the ability to change basket size| basket size changed to wanted size| -|Basket.cs|isPresent(int SKU_ID)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| -|Basket.cs|GetBagelCost(string name)| want to see the cost of a bagel| returns the price of given bagel| +|Basket.cs|ItemInBaskett(string type)| want to see if item is in basket so i only remove items present in basket| returns true if item in basket, false otherwise| +|Basket.cs|GetBagelCost(string bagelSKU)| want to see the cost of a bagel| returns the price of given bagel| |Basket.cs|GetTotalCost()| want to see total cost| returns the total cost of the basket| |Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| -|Inventory.cs|getFillingCost()| want to see price of fillings| returns list of fillings with price| -|Inventory.cs|inInventory(IProduct product)|only want to sell items in inventory|returns true if item in inventory, false otherwise| +|Inventory.cs|getFillingCost(string fillingSKU)| want to see price of fillings| returns list of fillings with price| +|Inventory.cs|inInventory(string item)|only want to sell items in inventory|returns true if item in inventory, false otherwise| diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index f65eac18..da41cb53 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -112,9 +112,8 @@ public void TestAddFilling() public void TestGetCostOfFilling() { Inventory inventory = new Inventory(); - Basket basket = new Basket(3, inventory); - Assert.That(basket.getFillingCost("FILE") == 0.12f); + Assert.That(inventory.getFillingCost("FILE") == 0.12f); } [Test] @@ -123,8 +122,8 @@ public void TestInInventory() Inventory inventory = new Inventory(); Basket basket = new Basket(3, inventory); - Assert.IsTrue(basket.inInventory("BGLO")); - Assert.IsFalse(basket.inInventory("egg")); + Assert.IsTrue(inventory.inInventory("BGLO")); + Assert.IsFalse(inventory.inInventory("egg")); } From 4615c571249bab41d44462625534ed87258f7ba6 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Mon, 11 Aug 2025 15:38:22 +0200 Subject: [PATCH 20/28] Stian Forren --- exercise.main/Inventory.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 34a3d062..747c3007 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -23,6 +23,10 @@ public Inventory() inventory.Add("FILX", new InvItem(7, 0.12f)); inventory.Add("FILS", new InvItem(8, 0.12f)); inventory.Add("FILH", new InvItem(9, 0.12f)); + inventory.Add("COFB", new InvItem(10, 0.12f)); + inventory.Add("COFW", new InvItem(11, 0.12f)); + inventory.Add("COFC", new InvItem(12, 0.12f)); + inventory.Add("COFL", new InvItem(13, 0.12f)); } From 0aabc23b529ba5cb53a0a549fd4d89e1aa849553 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 08:51:20 +0200 Subject: [PATCH 21/28] Stian Forren --- exercise.main/Basket.cs | 2 +- exercise.main/Enums.cs | 15 +++++++++++++++ exercise.main/IProduct.cs | 2 ++ exercise.main/InvItem.cs | 9 ++++++--- exercise.main/Inventory.cs | 28 ++++++++++++++-------------- exercise.main/Products/Bagel.cs | 8 ++++++++ exercise.main/Products/Filling.cs | 5 +++++ exercise.tests/CoreTest.cs | 31 +++++++++++++++++++++++++++++++ 8 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 exercise.main/Enums.cs diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 318c56a1..4e6e0f02 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -48,7 +48,7 @@ public float getBagelCost(string bagelSKU) public float getTotalCost() { - return ProductList.Sum(x => x.Price); + return ProductList.Sum(x => x.getTotalPrice()); } public float getFillingCost(string fillingSKU) diff --git a/exercise.main/Enums.cs b/exercise.main/Enums.cs new file mode 100644 index 00000000..67a5cb9b --- /dev/null +++ b/exercise.main/Enums.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main +{ + public enum Type + { + Bagel, + Coffee, + Filling + } +} diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index d8a4b1ed..7a232b36 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -11,5 +11,7 @@ public interface IProduct string SKU_NAME { get; set; } float Price { get; set; } + + float getTotalPrice(); } } diff --git a/exercise.main/InvItem.cs b/exercise.main/InvItem.cs index 238949f9..e1452378 100644 --- a/exercise.main/InvItem.cs +++ b/exercise.main/InvItem.cs @@ -10,17 +10,20 @@ public class InvItem { private int _id; private float _price; + private Type _type; - public InvItem(int setId, float setPrice) + public InvItem(int setId, float setPrice, Type type) { _price = setPrice; _id = setId; + _type = type; } public int ID { get { return _id; } } - public float Price { get { return _price; } + public float Price { get { return _price; } } + public Type Type { get { return _type; } } } -}} +} diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 747c3007..9ae6357d 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -13,20 +13,20 @@ public class Inventory public Inventory() { - inventory.Add("BGLO", new InvItem(0, 0.49f)); - inventory.Add("BGLP", new InvItem(1, 0.39f)); - inventory.Add("BGLE", new InvItem(2, 0.49f)); - inventory.Add("BGLS", new InvItem(3, 0.49f)); - inventory.Add("FILB", new InvItem(4, 0.12f)); - inventory.Add("FILE", new InvItem(5, 0.12f)); - inventory.Add("FILC", new InvItem(6, 0.12f)); - inventory.Add("FILX", new InvItem(7, 0.12f)); - inventory.Add("FILS", new InvItem(8, 0.12f)); - inventory.Add("FILH", new InvItem(9, 0.12f)); - inventory.Add("COFB", new InvItem(10, 0.12f)); - inventory.Add("COFW", new InvItem(11, 0.12f)); - inventory.Add("COFC", new InvItem(12, 0.12f)); - inventory.Add("COFL", new InvItem(13, 0.12f)); + inventory.Add("BGLO", new InvItem(0, 0.49f, Type.Bagel)); + inventory.Add("BGLP", new InvItem(1, 0.39f, Type.Bagel)); + inventory.Add("BGLE", new InvItem(2, 0.49f, Type.Bagel)); + inventory.Add("BGLS", new InvItem(3, 0.49f, Type.Bagel)); + inventory.Add("FILB", new InvItem(4, 0.12f, Type.Filling)); + inventory.Add("FILE", new InvItem(5, 0.12f, Type.Filling)); + inventory.Add("FILC", new InvItem(6, 0.12f, Type.Filling)); + inventory.Add("FILX", new InvItem(7, 0.12f, Type.Filling)); + inventory.Add("FILS", new InvItem(8, 0.12f, Type.Filling)); + inventory.Add("FILH", new InvItem(9, 0.12f, Type.Filling)); + inventory.Add("COFB", new InvItem(10, 0.12f, Type.Coffee)); + inventory.Add("COFW", new InvItem(11, 0.12f, Type.Coffee)); + inventory.Add("COFC", new InvItem(12, 0.12f, Type.Coffee)); + inventory.Add("COFL", new InvItem(13, 0.12f, Type.Coffee)); } diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs index d6503554..c3952a8d 100644 --- a/exercise.main/Products/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -28,5 +28,13 @@ public void addFilling(Filling filling) { fillings.Add(filling); } + public float costForFillings() + { + return fillings.Sum(x => x.Price); + } + public float getTotalPrice() + { + return fillings.Sum(x => x.getTotalPrice()) + _cost; + } } } diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs index a4fcd821..61a07454 100644 --- a/exercise.main/Products/Filling.cs +++ b/exercise.main/Products/Filling.cs @@ -18,5 +18,10 @@ public Filling(string name, Inventory inventory) } public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public float Price { get { return _cost; } set => new NotImplementedException(); } + + public float getTotalPrice() + { + return _cost; + } } } diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index da41cb53..a54e6bab 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -97,6 +97,21 @@ public void TestGetTotal() Assert.That(basket.getTotalCost() == 0.98f); } + [Test] + public void TestGetTotalWithAddedFillings() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + + basket.Add(bagel); + bagel.addFilling(new Filling("FILE", inventory)); + basket.Add(bagel2); + + Assert.That(basket.getTotalCost() == 1.10f); + } + [Test] public void TestAddFilling() { @@ -126,6 +141,22 @@ public void TestInInventory() Assert.IsFalse(inventory.inInventory("egg")); } + [Test] + public void TestcostForFillings() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + + Bagel bagel = new Bagel("BGLO", inventory); + + bagel.addFilling(new Filling("FILE", inventory)); + bagel.addFilling(new Filling("FILE", inventory)); + + Assert.That(bagel.costForFillings() == 0.24f); + + + } + } } From e83740c040a08fc01fff0c13c6f3549e98e850b3 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 10:28:02 +0200 Subject: [PATCH 22/28] Stian Forren --- exercise.main/Basket.cs | 21 ++++++++++++-- exercise.main/IProduct.cs | 2 ++ exercise.main/Products/Bagel.cs | 6 +++- exercise.main/Products/Coffee.cs | 31 +++++++++++++++++++++ exercise.main/Products/Filling.cs | 4 +++ exercise.main/Program.cs | 22 +++++++++++++-- exercise.tests/CoreTest.cs | 46 ++++++++++++++++++++++++++++++- 7 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 exercise.main/Products/Coffee.cs diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 4e6e0f02..df611cf0 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -1,4 +1,5 @@ -using System; +using exercise.main.Products; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -21,7 +22,10 @@ public Basket(int basketSize, Inventory inventory) public void Add(IProduct product) { - ProductList.Add(product); + if (!IsFull()) + { + ProductList.Add(product); + } } public void Remove(int placeInList) @@ -51,6 +55,11 @@ public float getTotalCost() return ProductList.Sum(x => x.getTotalPrice()); } + public float getTotalPriceForAllFillings() + { + return (float)Math.Round(ProductList.OfType().Sum(x => x.costForFillings()),2); + } + public float getFillingCost(string fillingSKU) { return _inventory.getFillingCost(fillingSKU); @@ -60,5 +69,13 @@ public bool inInventory(string item) { return _inventory.inInventory(item); } + + public Dictionary getItemCount() + { + Dictionary itemCount = new Dictionary(); + itemCount = ProductList.GroupBy(x => x).ToDictionary(g => g.Key.SKU_NAME, g => g.Count()); + + return itemCount; + } } } diff --git a/exercise.main/IProduct.cs b/exercise.main/IProduct.cs index 7a232b36..d6cea8e8 100644 --- a/exercise.main/IProduct.cs +++ b/exercise.main/IProduct.cs @@ -12,6 +12,8 @@ public interface IProduct float Price { get; set; } + Type type { get; } + float getTotalPrice(); } } diff --git a/exercise.main/Products/Bagel.cs b/exercise.main/Products/Bagel.cs index c3952a8d..abe799a0 100644 --- a/exercise.main/Products/Bagel.cs +++ b/exercise.main/Products/Bagel.cs @@ -13,17 +13,21 @@ public class Bagel : IProduct private string _NAME; private List fillings; private float _cost; + private Type _type; public Bagel(string name, Inventory inventory) { _NAME = name; fillings = new List(); _cost = inventory.inventory[name].Price; + _type = inventory.inventory[name].Type; } public string SKU_NAME { get { return _NAME; } set { _NAME = value; } } public float Price { get { return _cost; } set { _cost = value; } } public List Fillings { get { return fillings; } } + public Type type { get { return _type; } } + public void addFilling(Filling filling) { fillings.Add(filling); @@ -34,7 +38,7 @@ public float costForFillings() } public float getTotalPrice() { - return fillings.Sum(x => x.getTotalPrice()) + _cost; + return costForFillings() + _cost; } } } diff --git a/exercise.main/Products/Coffee.cs b/exercise.main/Products/Coffee.cs new file mode 100644 index 00000000..9c47941a --- /dev/null +++ b/exercise.main/Products/Coffee.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace exercise.main.Products +{ + public class Coffee : IProduct + { + private string _name; + private float _price; + private Type _type; + + public Coffee(string name, Inventory inventory) + { + _name = name; + _price = inventory.inventory[name].Price; + _type = inventory.inventory[name].Type; + } + public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public float Price { get { return _price; } set { _price = value; } } + + public Type type { get { return _type; } } + + public float getTotalPrice() + { + return _price; + } + } +} diff --git a/exercise.main/Products/Filling.cs b/exercise.main/Products/Filling.cs index 61a07454..80e15b1f 100644 --- a/exercise.main/Products/Filling.cs +++ b/exercise.main/Products/Filling.cs @@ -10,15 +10,19 @@ public class Filling : IProduct { private string _name; private float _cost; + private Type _type; public Filling(string name, Inventory inventory) { _name = name; _cost = inventory.inventory[name].Price; + _type = inventory.inventory[name].Type; } public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } public float Price { get { return _cost; } set => new NotImplementedException(); } + public Type type { get { return _type; } } + public float getTotalPrice() { return _cost; diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 3751555c..43c1c738 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,2 +1,20 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using exercise.main; +using exercise.main.Products; + +Inventory inventory = new Inventory(); +Basket basket = new Basket(3, inventory); + +Bagel bagel = new Bagel("BGLO", inventory); +Bagel bagel2 = new Bagel("BGLE", inventory); +Bagel bagel3 = new Bagel("BGLO", inventory); + +bagel.addFilling(new Filling("FILE", inventory)); +bagel.addFilling(new Filling("FILE", inventory)); +bagel2.addFilling(new Filling("FILB", inventory)); + +basket.Add(bagel); +basket.Add(bagel2); +basket.Add(bagel3); + +basket.getTotalPriceForAllFillings(); + diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index a54e6bab..c762d09f 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -158,5 +158,49 @@ public void TestcostForFillings() } - } + [Test] + public void TestGetItemCount() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(15, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + basket.Add(bagel); + basket.Add(bagel); + for (int i = 0; i < 10; i++) + { + basket.Add(bagel2); + } + + Dictionary itemCount = basket.getItemCount(); + + Assert.That(itemCount["BGLO"] == 2); + Assert.That(itemCount["BGLE"] == 10); + } + + [Test] + public void TestGetTotalPriceForAllFillings() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(3, inventory); + + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + Bagel bagel3 = new Bagel("BGLO", inventory); + + bagel.addFilling(new Filling("FILE", inventory)); + bagel.addFilling(new Filling("FILE", inventory)); + bagel2.addFilling(new Filling("FILB", inventory)); + + basket.Add(bagel); + basket.Add(bagel2); + basket.Add(bagel3); + + + Assert.That(basket.getTotalPriceForAllFillings() == 0.36f); + + + } + + } } From 3e91e0f0fed2334a7bf4d125e3a04ee5853191dd Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 13:22:49 +0200 Subject: [PATCH 23/28] Stian Forren --- exercise.main/Basket.cs | 72 +++++++++++++++++++++++++++++-- exercise.main/Products/Coffee.cs | 2 +- exercise.main/Program.cs | 21 +++++---- exercise.tests/CoreTest.cs | 74 ++++++++++++++++++++++++++++++++ 4 files changed, 154 insertions(+), 15 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index df611cf0..d9dc50a3 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -50,6 +50,11 @@ public float getBagelCost(string bagelSKU) return _inventory.inventory[bagelSKU].Price; } + public float getTotalCostForBagels() + { + return ProductList.OfType().Sum(x => x.Price); + } + public float getTotalCost() { return ProductList.Sum(x => x.getTotalPrice()); @@ -57,7 +62,7 @@ public float getTotalCost() public float getTotalPriceForAllFillings() { - return (float)Math.Round(ProductList.OfType().Sum(x => x.costForFillings()),2); + return (float)Math.Round(ProductList.OfType().Sum(x => x.costForFillings()), 2); } public float getFillingCost(string fillingSKU) @@ -69,13 +74,74 @@ public bool inInventory(string item) { return _inventory.inInventory(item); } - + public Dictionary getItemCount() { Dictionary itemCount = new Dictionary(); - itemCount = ProductList.GroupBy(x => x).ToDictionary(g => g.Key.SKU_NAME, g => g.Count()); + itemCount = ProductList.GroupBy(x => x).ToDictionary(g => g.Key.SKU_NAME, g => g.Count()); return itemCount; } + + public float caluculateDiscount() + { + Dictionary itemCount = getItemCount(); + float discountPice = 0; + if (checkIfBundleDealAvaiable(itemCount)) + { + foreach (var item in itemCount) + { + if (item.Value >= 6 && _inventory.inventory[item.Key].Type == Type.Bagel) + { + discountPice += getPriceForItemWithBundleDiscount(item.Key, item.Value); + } + } + } + return discountPice; + } + + public bool checkIfBundleDealAvaiable(Dictionary dict) + { + foreach (var item in dict) + { + if (item.Value >= 6 && _inventory.inventory[item.Key].Type == Type.Bagel) + { + return true; + } + } + return false; + } + + public bool checkIfCoffeeDealAvailable(Dictionary dict) + { + return (ProductList.Any(x => _inventory.inventory[x.SKU_NAME].Type == Type.Bagel) + && ProductList.Any(y => _inventory.inventory[y.SKU_NAME].Type == Type.Coffee)); + } + + public float getPriceForItemWithBundleDiscount(string bagel, int amount) + { + int twelveBundle = 0; + int sixBundle = 0; + int singles = 0; + + if (amount >= 12) + { + twelveBundle = amount/12; + singles = amount%12; + if (singles > 6) + { + sixBundle = singles/6; + singles = singles%6; + } + } + else if (amount > 6) + { + sixBundle = singles / 6; + singles = singles % 6; + + } + return twelveBundle * 3.99f + sixBundle * 2.49f + singles * _inventory.inventory[bagel].Price; + } + } } diff --git a/exercise.main/Products/Coffee.cs b/exercise.main/Products/Coffee.cs index 9c47941a..977c7243 100644 --- a/exercise.main/Products/Coffee.cs +++ b/exercise.main/Products/Coffee.cs @@ -18,7 +18,7 @@ public Coffee(string name, Inventory inventory) _price = inventory.inventory[name].Price; _type = inventory.inventory[name].Type; } - public string SKU_NAME { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + public string SKU_NAME { get { return _name; } set => throw new NotImplementedException(); } public float Price { get { return _price; } set { _price = value; } } public Type type { get { return _type; } } diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 43c1c738..4f1f69e5 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -1,20 +1,19 @@ using exercise.main; using exercise.main.Products; -Inventory inventory = new Inventory(); -Basket basket = new Basket(3, inventory); +Inventory inventory = new Inventory(); +Basket basket = new Basket(20, inventory); Bagel bagel = new Bagel("BGLO", inventory); Bagel bagel2 = new Bagel("BGLE", inventory); -Bagel bagel3 = new Bagel("BGLO", inventory); - -bagel.addFilling(new Filling("FILE", inventory)); -bagel.addFilling(new Filling("FILE", inventory)); -bagel2.addFilling(new Filling("FILB", inventory)); +//basket.Add(bagel); +//basket.Add(bagel); +for (int i = 0; i < 20; i++) +{ + basket.Add(bagel2); +} -basket.Add(bagel); -basket.Add(bagel2); -basket.Add(bagel3); -basket.getTotalPriceForAllFillings(); +float total = basket.caluculateDiscount(); +Console.WriteLine(total); \ No newline at end of file diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index c762d09f..31cb312d 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -198,9 +198,83 @@ public void TestGetTotalPriceForAllFillings() Assert.That(basket.getTotalPriceForAllFillings() == 0.36f); + } + + [Test] + public void TestCheckIfBundleDealAvailable() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(15, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + basket.Add(bagel); + basket.Add(bagel); + for (int i = 0; i < 10; i++) + { + basket.Add(bagel2); + } + + Dictionary itemCount = basket.getItemCount(); + + Assert.IsTrue(basket.checkIfBundleDealAvaiable(itemCount)); + Assert.IsFalse(basket.checkIfCoffeeDealAvailable(itemCount)); + } + + [Test] + public void TestCheckIfCoffeeDealAvailable() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(15, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + basket.Add(bagel); + basket.Add(bagel); + basket.Add(new Coffee("COFB", inventory)); + + Dictionary itemCount = basket.getItemCount(); + Assert.IsFalse(basket.checkIfBundleDealAvaiable(itemCount)); + Assert.IsTrue(basket.checkIfCoffeeDealAvailable(itemCount)); + } + [Test] + public void TestCalculateDiscount() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(120, inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + for (int i = 0; i < 20; i++) + { + basket.Add(bagel2); + } + + + Assert.That(basket.caluculateDiscount() == 7.46f); + + } + [Test] + public void TestGetToalCostOfBagels() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(15, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLE", inventory); + bagel.addFilling(new Filling("FILE", inventory)); + bagel.addFilling(new Filling("FILE", inventory)); + bagel2.addFilling(new Filling("FILE", inventory)); + basket.Add(bagel); + basket.Add(bagel); + basket.Add(new Coffee("COFB", inventory)); + for (int i = 0; i < 3; i++) + { + basket.Add(bagel2); + } + + + Assert.That(basket.getTotalCostForBagels() == 2.45f); + + } } } From 9fe5e8c3abbe0955ca701df1be779a4cf09d6925 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 14:50:33 +0200 Subject: [PATCH 24/28] added discount --- exercise.main/Basket.cs | 62 ++++++++++++++++++++++++++++--- exercise.main/Inventory.cs | 8 ++-- exercise.main/Program.cs | 22 +++++------ exercise.tests/CoreTest.cs | 76 ++++++++++++++++++++++++++++++++++---- 4 files changed, 138 insertions(+), 30 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index d9dc50a3..91ddcd0d 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -86,18 +87,67 @@ public Dictionary getItemCount() public float caluculateDiscount() { Dictionary itemCount = getItemCount(); - float discountPice = 0; + float discountPrice = 0; if (checkIfBundleDealAvaiable(itemCount)) { foreach (var item in itemCount) { if (item.Value >= 6 && _inventory.inventory[item.Key].Type == Type.Bagel) { - discountPice += getPriceForItemWithBundleDiscount(item.Key, item.Value); + discountPrice += getPriceForItemWithBundleDiscount(item.Key, item.Value); + } + else + { + discountPrice += item.Value * _inventory.inventory[item.Key].Price; + } + } + return discountPrice; + } + else if (checkIfCoffeeDealAvailable(itemCount)) + { + List coffeeList = TypeList(itemCount, Type.Coffee); + List bagelList = TypeList(itemCount, Type.Bagel); + int numberOfCoffee = coffeeList.Count; + int numberOfBagel = bagelList.Count; + + for (int i = 0; i < Math.Min(numberOfCoffee, numberOfBagel); i++) + { + itemCount[coffeeList[i]] -= 1; + itemCount[bagelList[i]] -= 1; + discountPrice += 1.25f; + } + foreach (var item in itemCount) + { + + discountPrice += item.Value * _inventory.inventory[item.Key].Price; + } + return discountPrice; + } + else + { + foreach (var item in itemCount) + { + + discountPrice += item.Value * _inventory.inventory[item.Key].Price; + } + return discountPrice; + } + } + + public List TypeList(Dictionary dict, Type type) + { + List typeList = new List(); + foreach (var item in dict) + { + if (_inventory.inventory[item.Key].Type == type) + { + for (int i = 0; i < item.Value; i++) + { + typeList.Add(item.Key); } } } - return discountPice; + return typeList; } public bool checkIfBundleDealAvaiable(Dictionary dict) @@ -134,10 +184,10 @@ public float getPriceForItemWithBundleDiscount(string bagel, int amount) singles = singles%6; } } - else if (amount > 6) + else if (amount >= 6) { - sixBundle = singles / 6; - singles = singles % 6; + sixBundle = amount / 6; + singles = amount % 6; } return twelveBundle * 3.99f + sixBundle * 2.49f + singles * _inventory.inventory[bagel].Price; diff --git a/exercise.main/Inventory.cs b/exercise.main/Inventory.cs index 9ae6357d..b2144df5 100644 --- a/exercise.main/Inventory.cs +++ b/exercise.main/Inventory.cs @@ -23,10 +23,10 @@ public Inventory() inventory.Add("FILX", new InvItem(7, 0.12f, Type.Filling)); inventory.Add("FILS", new InvItem(8, 0.12f, Type.Filling)); inventory.Add("FILH", new InvItem(9, 0.12f, Type.Filling)); - inventory.Add("COFB", new InvItem(10, 0.12f, Type.Coffee)); - inventory.Add("COFW", new InvItem(11, 0.12f, Type.Coffee)); - inventory.Add("COFC", new InvItem(12, 0.12f, Type.Coffee)); - inventory.Add("COFL", new InvItem(13, 0.12f, Type.Coffee)); + inventory.Add("COFB", new InvItem(10, 0.99f, Type.Coffee)); + inventory.Add("COFW", new InvItem(11, 1.19f, Type.Coffee)); + inventory.Add("COFC", new InvItem(12, 1.29f, Type.Coffee)); + inventory.Add("COFL", new InvItem(13, 1.29f, Type.Coffee)); } diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index 4f1f69e5..fa67cca0 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -3,17 +3,15 @@ Inventory inventory = new Inventory(); -Basket basket = new Basket(20, inventory); -Bagel bagel = new Bagel("BGLO", inventory); -Bagel bagel2 = new Bagel("BGLE", inventory); -//basket.Add(bagel); -//basket.Add(bagel); -for (int i = 0; i < 20; i++) +Basket basket = new Basket(30, inventory); +Bagel bagel = new Bagel("BGLP", inventory); +Coffee coffee = new Coffee("COFB", inventory); +for (int i = 0; i < 4; i++) { - basket.Add(bagel2); + basket.Add(bagel); } - - - -float total = basket.caluculateDiscount(); -Console.WriteLine(total); \ No newline at end of file +for (int i = 0; i < 2; i++) +{ + basket.Add(coffee); +} +Console.WriteLine(basket.caluculateDiscount()); \ No newline at end of file diff --git a/exercise.tests/CoreTest.cs b/exercise.tests/CoreTest.cs index 31cb312d..561aa5a8 100644 --- a/exercise.tests/CoreTest.cs +++ b/exercise.tests/CoreTest.cs @@ -15,7 +15,7 @@ public class CoreTest public void TestAdd() { Inventory inventory = new Inventory(); - Basket basket = new Basket(3,inventory); + Basket basket = new Basket(3, inventory); Bagel bagel = new Bagel("BGLO", inventory); basket.Add(bagel); @@ -26,7 +26,7 @@ public void TestAdd() public void TestRemove() { Inventory inventory = new Inventory(); - Basket basket = new Basket(3, inventory); + Basket basket = new Basket(3, inventory); Bagel bagel = new Bagel("BGLO", inventory); basket.Add(bagel); @@ -40,9 +40,9 @@ public void TestIsFull() { Inventory inventory = new Inventory(); Basket basket = new Basket(3, inventory); - Bagel bagel = new Bagel("BGLO",inventory); - Bagel bagel2 = new Bagel("BGLO",inventory); - Bagel bagel3 = new Bagel("BGLO",inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLO", inventory); + Bagel bagel3 = new Bagel("BGLO", inventory); basket.Add(bagel); Assert.IsFalse(basket.IsFull()); @@ -195,7 +195,7 @@ public void TestGetTotalPriceForAllFillings() basket.Add(bagel); basket.Add(bagel2); basket.Add(bagel3); - + Assert.That(basket.getTotalPriceForAllFillings() == 0.36f); } @@ -251,7 +251,7 @@ public void TestCalculateDiscount() Assert.That(basket.caluculateDiscount() == 7.46f); - + } [Test] @@ -272,9 +272,69 @@ public void TestGetToalCostOfBagels() basket.Add(bagel2); } - Assert.That(basket.getTotalCostForBagels() == 2.45f); } + + [Test] + public void TestDiscounts1() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(30, inventory); + Bagel bagel = new Bagel("BGLO", inventory); + Bagel bagel2 = new Bagel("BGLP", inventory); + Bagel bagel3 = new Bagel("BGLE", inventory); + Coffee coffee = new Coffee("COFB", inventory); + basket.Add(bagel); + basket.Add(bagel); + for (int i = 0; i < 12; i++) + { + basket.Add(bagel2); + } + for (int i = 0; i < 6; i++) + { + basket.Add(bagel3); + } + for (int i = 0; i < 3; i++) + { + basket.Add(coffee); + } + + Assert.That(basket.caluculateDiscount() == 10.43f); + } + [Test] + public void TestDiscounts2() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(30, inventory); + Bagel bagel = new Bagel("BGLP", inventory); + for (int i = 0; i < 16; i++) + { + basket.Add(bagel); + } + + + Assert.That(basket.caluculateDiscount() == 5.55f); + } + + [Test] + public void TestDiscounts3() + { + Inventory inventory = new Inventory(); + Basket basket = new Basket(30, inventory); + Bagel bagel = new Bagel("BGLP", inventory); + Coffee coffee = new Coffee("COFB", inventory); + for (int i = 0; i < 4; i++) + { + basket.Add(bagel); + } + for (int i = 0; i < 2; i++) + { + basket.Add(coffee); + } + + Assert.That(basket.caluculateDiscount() == 3.28f); + } + } } From ec6f497db6d3b04aefe5abc1a727c9a63ab8d46a Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 15:36:28 +0200 Subject: [PATCH 25/28] ReceiptBuilder --- exercise.main/Basket.cs | 24 ++++++++++++++++++++++-- exercise.main/Program.cs | 7 ++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 91ddcd0d..6bbaea67 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -164,8 +164,8 @@ public bool checkIfBundleDealAvaiable(Dictionary dict) public bool checkIfCoffeeDealAvailable(Dictionary dict) { - return (ProductList.Any(x => _inventory.inventory[x.SKU_NAME].Type == Type.Bagel) - && ProductList.Any(y => _inventory.inventory[y.SKU_NAME].Type == Type.Coffee)); + return (dict.Any(x => _inventory.inventory[x.Key].Type == Type.Bagel) + && dict.Any(y => _inventory.inventory[y.Key].Type == Type.Coffee)); } public float getPriceForItemWithBundleDiscount(string bagel, int amount) @@ -193,5 +193,25 @@ public float getPriceForItemWithBundleDiscount(string bagel, int amount) return twelveBundle * 3.99f + sixBundle * 2.49f + singles * _inventory.inventory[bagel].Price; } + + public string BuildReceipt() + { + StringBuilder receipt = new StringBuilder(); + DateTime dateTime = DateTime.Now; + Dictionary itemCount = getItemCount(); + string test = "longer"; + + receipt.AppendLine("***** Bob's Bagels ******"); + receipt.AppendLine($" {dateTime.ToString()}"); + receipt.AppendLine("--------------------------"); + foreach (var item in itemCount) + { + receipt.AppendLine($"{item.Key,-15}{item.Value,-7}{_inventory.inventory[item.Key].Price * item.Value,2}"); + } + receipt.AppendLine("--------------------------"); + receipt.AppendLine($"Total:{Math.Round(getTotalCost(),2),20}"); + return receipt.ToString(); + } + } } diff --git a/exercise.main/Program.cs b/exercise.main/Program.cs index fa67cca0..2714f859 100644 --- a/exercise.main/Program.cs +++ b/exercise.main/Program.cs @@ -5,6 +5,7 @@ Inventory inventory = new Inventory(); Basket basket = new Basket(30, inventory); Bagel bagel = new Bagel("BGLP", inventory); +Bagel bagel2 = new Bagel("BGLE", inventory); Coffee coffee = new Coffee("COFB", inventory); for (int i = 0; i < 4; i++) { @@ -14,4 +15,8 @@ { basket.Add(coffee); } -Console.WriteLine(basket.caluculateDiscount()); \ No newline at end of file +for (int i = 0; i < 7; i++) +{ + basket.Add(bagel2); +} +Console.WriteLine(basket.BuildReceipt()); \ No newline at end of file From 98604653c50ac0c9ae69e6d88e3e8928c6dddd9d Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Tue, 12 Aug 2025 15:43:20 +0200 Subject: [PATCH 26/28] receipt --- exercise.main/Basket.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index 6bbaea67..f1330874 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -1,6 +1,7 @@ using exercise.main.Products; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Numerics; using System.Text; @@ -206,7 +207,7 @@ public string BuildReceipt() receipt.AppendLine("--------------------------"); foreach (var item in itemCount) { - receipt.AppendLine($"{item.Key,-15}{item.Value,-7}{_inventory.inventory[item.Key].Price * item.Value,2}"); + receipt.AppendLine($"{item.Key,-15}{item.Value,-6}£{_inventory.inventory[item.Key].Price * item.Value}"); } receipt.AppendLine("--------------------------"); receipt.AppendLine($"Total:{Math.Round(getTotalCost(),2),20}"); From 7c3ef45b8840e87559d35b564f9c44a57f81cbd3 Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Wed, 13 Aug 2025 08:50:31 +0200 Subject: [PATCH 27/28] userstories and domainmodel --- exercise.main/domainModel.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/exercise.main/domainModel.md b/exercise.main/domainModel.md index f367e0fb..a16114ed 100644 --- a/exercise.main/domainModel.md +++ b/exercise.main/domainModel.md @@ -10,3 +10,30 @@ |Bagel.cs|AddFilling(IProduct filling)| want to add filling| wanted filling added| |Inventory.cs|getFillingCost(string fillingSKU)| want to see price of fillings| returns list of fillings with price| |Inventory.cs|inInventory(string item)|only want to sell items in inventory|returns true if item in inventory, false otherwise| +|Basket.cs|CalculateDiscount()|so if items in basket are discountable, give the discount| Total price deiscounted| +|basket.cs|checkIfBundleDealAvailable()|so i can get discounted price when buying in bulk| returns true if bulk criteria is met| +|basket.cs|checkOfCoffeeDealAvailable()|so i can get dicounted price when buying both a bagel and a coffee|returns true if coffeedeal available| +|basket.cs|BuildReceipt()|so i can recieve a receipt|builds and return a reciept of the purchased items| + + + + +1. +As a regular customer +So I can justify the spendings for this shop, +I'd like to have some sort of coffee bagel deal. + +2. +As a parent, +So i can by bagel to the whole family +I would like to be able to buy bundles of bagels for a discounted price. + +3. +As a member of the public, +So I can check my order, +I would like to be able to recieve a receipt of my purchase + +4. +As an organised person, +So I can organise my reciept, +I would like a timestamp on the reciept From 0524c99845f08c3e8ca5da80e499d330bffde75a Mon Sep 17 00:00:00 2001 From: Stian Forren Date: Wed, 13 Aug 2025 09:14:28 +0200 Subject: [PATCH 28/28] removed line --- exercise.main/Basket.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/exercise.main/Basket.cs b/exercise.main/Basket.cs index f1330874..8b85211b 100644 --- a/exercise.main/Basket.cs +++ b/exercise.main/Basket.cs @@ -200,7 +200,6 @@ public string BuildReceipt() StringBuilder receipt = new StringBuilder(); DateTime dateTime = DateTime.Now; Dictionary itemCount = getItemCount(); - string test = "longer"; receipt.AppendLine("***** Bob's Bagels ******"); receipt.AppendLine($" {dateTime.ToString()}");