From 2725b7542765e3e5b86f91c8894abc40223bac1c Mon Sep 17 00:00:00 2001 From: panfi98 Date: Wed, 14 Aug 2024 10:51:53 +0200 Subject: [PATCH 1/5] Finished with exersize 1, want to see how the table will turn out --- domain-model.md | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/domain-model.md b/domain-model.md index 653f474..a351bc2 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,27 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +Story +As a supermarket shopper, +So that I can pay for products at checkout, +I'd like to be able to know the total cost of items in my basket. + + +Model + +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------------------|------------------------|---------------------------| +| `SuperMarket` | `itemCostCalculator(Dictionary receipt)`| sum up item cost (keys)| total cost (int total) | +| | | | | + +Story +As an organised individual, +So that I can evaluate my shopping habits, +I'd like to see an itemised receipt that includes the name and price of the products +I bought as well as the quantity, and a total cost of my basket. + +Model + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------------------|---------------------------------------------------------|---------------------------| +| `SuperMarket` | `showReceipt(Dictionary receipt, int total)`| print items with their costs, and total cost at the end | printed receipt on console| +| | | | | \ No newline at end of file From 4e2bf5a910ab85ddc56d1ec6a7ee93843a7936c3 Mon Sep 17 00:00:00 2001 From: panfi98 Date: Wed, 14 Aug 2024 10:56:08 +0200 Subject: [PATCH 2/5] adjusted the tables --- domain-model.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/domain-model.md b/domain-model.md index a351bc2..b1fb66f 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,26 +1,28 @@ #Domain Models In Here -Story +Story +
As a supermarket shopper, So that I can pay for products at checkout, I'd like to be able to know the total cost of items in my basket. -Model - +Model +
| Classes | Methods | Scenario | Outputs | |-----------------|-----------------------------------------------------|------------------------|---------------------------| | `SuperMarket` | `itemCostCalculator(Dictionary receipt)`| sum up item cost (keys)| total cost (int total) | | | | | | - -Story -As an organised individual, +
+Story +
+As an organized individual, So that I can evaluate my shopping habits, -I'd like to see an itemised receipt that includes the name and price of the products +I'd like to see an itemized receipt that includes the name and price of the products I bought as well as the quantity, and a total cost of my basket. -Model - +Model +
| Classes | Methods | Scenario | Outputs | |-----------------|---------------------------------------------------------|---------------------------------------------------------|---------------------------| | `SuperMarket` | `showReceipt(Dictionary receipt, int total)`| print items with their costs, and total cost at the end | printed receipt on console| From d7d8729adc3577304d1dc37237715de524365e46 Mon Sep 17 00:00:00 2001 From: panfi98 Date: Wed, 14 Aug 2024 11:13:00 +0200 Subject: [PATCH 3/5] adjusted tables even more, expended them a little bit, and added more logic --- domain-model.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/domain-model.md b/domain-model.md index b1fb66f..3314d80 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,5 +1,3 @@ -#Domain Models In Here - Story
As a supermarket shopper, @@ -11,7 +9,7 @@ I'd like to be able to know the total cost of items in my basket.
| Classes | Methods | Scenario | Outputs | |-----------------|-----------------------------------------------------|------------------------|---------------------------| -| `SuperMarket` | `itemCostCalculator(Dictionary receipt)`| sum up item cost (keys)| total cost (int total) | +| `SuperMarket` | `itemCostCalculator(Dictionary receipt)`| Sum up item cost (keys)| Total cost (int total) | | | | | |
Story @@ -25,5 +23,5 @@ I bought as well as the quantity, and a total cost of my basket.
| Classes | Methods | Scenario | Outputs | |-----------------|---------------------------------------------------------|---------------------------------------------------------|---------------------------| -| `SuperMarket` | `showReceipt(Dictionary receipt, int total)`| print items with their costs, and total cost at the end | printed receipt on console| +| `SuperMarket` | `showReceipt(Dictionary receipt, int total)`| Print items with their costs, and total cost at the end | Printed receipt on console| | | | | | \ No newline at end of file From 73f9e03453fb2b8b6e74410af74b3a471b7b9372 Mon Sep 17 00:00:00 2001 From: panfi98 Date: Wed, 14 Aug 2024 11:14:37 +0200 Subject: [PATCH 4/5] a mistake with previous push, now it should be right --- domain-model.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/domain-model.md b/domain-model.md index 3314d80..f30fc60 100644 --- a/domain-model.md +++ b/domain-model.md @@ -7,10 +7,16 @@ I'd like to be able to know the total cost of items in my basket. Model
-| Classes | Methods | Scenario | Outputs | -|-----------------|-----------------------------------------------------|------------------------|---------------------------| -| `SuperMarket` | `itemCostCalculator(Dictionary receipt)`| Sum up item cost (keys)| Total cost (int total) | -| | | | | +| Classes | Methods | Scenario | Outputs | +|-----------------|-----------------------------------------------------------------------------------------|-------------------------------|---------------------------| +| `SuperMarket` | `itemInBasket(string itemName, decimal itemPrice, Dictionary receipt)` | Item is in not in the basket | true | +| | | | | +| | `itemInBasket(Dictionary receipt)` | Item is not in the basket | false | +| | | | | +| | `putItemInBasket(Dictionary receipt, bool isItemInBasket)` | | | +| | | | | +| | `costCalculate(Dictionary receipt)` | | Total cost (int total) | +| | | | |
Story
From 912e040a58c40427da29281221e13c4d51405c6b Mon Sep 17 00:00:00 2001 From: panfi98 Date: Wed, 14 Aug 2024 14:14:22 +0200 Subject: [PATCH 5/5] Finished with exersize two --- tdd-domain-modelling.CSharp.Main/Basket.cs | 35 +++++++++++++++ .../BasketTests.cs | 44 +++++++++++++++++++ .../CohortManagerTests.cs | 2 + 3 files changed, 81 insertions(+) create mode 100644 tdd-domain-modelling.CSharp.Main/Basket.cs create mode 100644 tdd-domain-modelling.CSharp.Test/BasketTests.cs diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..fc56b2c --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,35 @@ + + +namespace tdd_domain_modelling.CSharp.Test +{ + public class Basket + { + private Dictionary _items = new Dictionary(); + private decimal _total = 0; + + + public bool Add(string item, decimal price) + { + if (_items.ContainsKey(item)) + { + + return false; + } + else + { + _items.Add(item, price); + return true; + } + } + + public decimal Total() + { + foreach (int value in _items.Values) + { + _total += value; + } + + return _total; + } + } +} \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/BasketTests.cs b/tdd-domain-modelling.CSharp.Test/BasketTests.cs new file mode 100644 index 0000000..214dfa5 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTests.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using tdd_domain_modelling.CSharp.Main; + + +namespace tdd_domain_modelling.CSharp.Test +{ + [TestFixture] + public class BasketTests + { + [TestCase("Bread", 0.99, true)] + [TestCase("Kinder Surprise", 0.99, false)] + public void TestAdd(string item, decimal price, bool isItemPresent) + { + //arrange + Basket basket = new Basket(); + + basket.Add("Apple 100g", 2.49m); + basket.Add("Carrot 100g", 1.99m); + basket.Add("Kinder Surprise", 0.99m); + + + //act + bool result1 = basket.Add(item, price); + + //assert + Assert.AreEqual(isItemPresent, result1); + + } + [TestCase(9)] + public void TestTotal(decimal expected) + { + //arrange + Basket basket = new Basket(); + basket.Add("Apple 100g", 2); + basket.Add("Carrot 100g", 3); + basket.Add("Kinder Surprise", 4); + //act + decimal result = basket.Total(); + + //assert + Assert.IsTrue(result == expected); + } + } +} \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs index 56f3873..7b324a0 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -10,6 +10,8 @@ public class CohortManagerTest public void FirstTest() { CohortManager core = new CohortManager(); + + } } } \ No newline at end of file