From 9122a2f4dbc46f0db50be691c6c9d0ca6279f513 Mon Sep 17 00:00:00 2001 From: Elsa-tech <74308633+Elsa-tech@users.noreply.github.com> Date: Fri, 12 Jan 2024 11:52:57 +0100 Subject: [PATCH 1/6] Update exercise1.md --- exercise1.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/exercise1.md b/exercise1.md index 35588dd..25f40a9 100644 --- a/exercise1.md +++ b/exercise1.md @@ -24,9 +24,12 @@ Here is how one might design a domain model for the above user story: > **Time to analyse** > > Evaluate the user story and the domain model above. What assumptions did the developer have to make and what would you do differently? -> +The List in Methods could have been concisting of Objects instead of string. The output is of boolean value. The user could have wanted the whoule course if it was a object with other attributes. Name of class could be different. You would not necessary have to pass the list of cohorts as well as the string. > Create your own domain model for the user story above, try to come up with a different solution than the model provided. You can use a table like the one above, a spreadsheet, pen and paper, whatever you'd like. Share your work in your cohorts classroom channel when you're done. - +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `CohortManager` | `search(List cohorts, String name)` | If name is in list | true | +| | | If name is not in list | false | ### Exercise Follow the same process as above to translate these two user stories into domain models. @@ -49,4 +52,4 @@ I bought as well as the quantity, and a total cost of my basket. - Your model doesn't have to look like the example provided in this file. If you feel like you need more or less columns, feel free to go with that. There is no "right way" to do this kind of thing, we're just - designing a system to make our lives easier when it comes to the coding part. \ No newline at end of file + designing a system to make our lives easier when it comes to the coding part. From 9c1b938790a6a4c988beebe2aad3972a3ec4eae5 Mon Sep 17 00:00:00 2001 From: Elsa-tech <74308633+Elsa-tech@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:59:52 +0100 Subject: [PATCH 2/6] Update exercise1.md - wip --- exercise1.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/exercise1.md b/exercise1.md index 25f40a9..2c5f7ee 100644 --- a/exercise1.md +++ b/exercise1.md @@ -24,12 +24,17 @@ Here is how one might design a domain model for the above user story: > **Time to analyse** > > Evaluate the user story and the domain model above. What assumptions did the developer have to make and what would you do differently? -The List in Methods could have been concisting of Objects instead of string. The output is of boolean value. The user could have wanted the whoule course if it was a object with other attributes. Name of class could be different. You would not necessary have to pass the list of cohorts as well as the string. +> The List in Methods could have been concisting of Objects instead of string. The output is of boolean value. +> The user could have wanted the whoule course if it was a object with other attributes. +> Name of class could be different. You would not necessary have to pass the list of cohorts as well as the string. +> > Create your own domain model for the user story above, try to come up with a different solution than the model provided. You can use a table like the one above, a spreadsheet, pen and paper, whatever you'd like. Share your work in your cohorts classroom channel when you're done. +> +> | Classes | Methods | Scenario | Outputs | |-----------------|---------------------------------------------|------------------------|---------| -| `CohortManager` | `search(List cohorts, String name)` | If name is in list | true | -| | | If name is not in list | false | +| `CohortManager` | `find(List cohorts, String name) `| If name is in list |Cohort c| +| | | If name is not in list |Exception| ### Exercise Follow the same process as above to translate these two user stories into domain models. @@ -39,12 +44,22 @@ 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. ``` - +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `Supermarket ` | `double Sum(List products)` | Sum prices together | double sum| + ``` 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. +``` +``` +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +|`Product` | `double Total(List products)` | Sum prices | double sum | +| `Receipt` | `` + ``` - Add your domain models as images to the project, or in the `domain-model.md` file. From 3abaca0239594ea60df5ce5187423bd82a2df2e8 Mon Sep 17 00:00:00 2001 From: Elsa-tech <74308633+Elsa-tech@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:41:05 +0100 Subject: [PATCH 3/6] Update exercise1.md Added tables --- exercise1.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/exercise1.md b/exercise1.md index 2c5f7ee..da5d90c 100644 --- a/exercise1.md +++ b/exercise1.md @@ -33,7 +33,7 @@ Here is how one might design a domain model for the above user story: > | Classes | Methods | Scenario | Outputs | |-----------------|---------------------------------------------|------------------------|---------| -| `CohortManager` | `find(List cohorts, String name) `| If name is in list |Cohort c| +| `CohortManager` | `find(List cohorts, String name) `| If name is in list |Cohort c | | | | If name is not in list |Exception| ### Exercise @@ -44,8 +44,8 @@ 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. ``` -| Classes | Methods | Scenario | Outputs | -|-----------------|---------------------------------------------|------------------------|---------| +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|--------- | | `Supermarket ` | `double Sum(List products)` | Sum prices together | double sum| ``` @@ -54,13 +54,15 @@ 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. ``` -``` -| Classes | Methods | Scenario | Outputs | -|-----------------|---------------------------------------------|------------------------|---------| -|`Product` | `double Total(List products)` | Sum prices | double sum | -| `Receipt` | `` - -``` + +| Classes | Members |Methods | Scenario | Outputs | +|-----------------|----------------------|-------------------------|------------------------|------------| +|`Product` | `string code, double price`, int quantity| | | | + +|`Reciept` |`List prods` |`double SumOfProducts() `|Add prods.price * prods.quantity | return sum + + + - Add your domain models as images to the project, or in the `domain-model.md` file. From 9c34e8458359147d9e6517522c5d936c07833aaf Mon Sep 17 00:00:00 2001 From: Elsa-tech <74308633+Elsa-tech@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:43:23 +0100 Subject: [PATCH 4/6] Update exercise1.md --- exercise1.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/exercise1.md b/exercise1.md index da5d90c..73420c2 100644 --- a/exercise1.md +++ b/exercise1.md @@ -57,9 +57,8 @@ I bought as well as the quantity, and a total cost of my basket. | Classes | Members |Methods | Scenario | Outputs | |-----------------|----------------------|-------------------------|------------------------|------------| -|`Product` | `string code, double price`, int quantity| | | | - -|`Reciept` |`List prods` |`double SumOfProducts() `|Add prods.price * prods.quantity | return sum +|`Product` | `string code, double price, int quantity`| | | | +|`Reciept` |`List prods` |`double SumOfProducts() `|Add prods.price * prods.quantity | return sum | From 448f242ddfd0594b422580d0d555c513b64898df Mon Sep 17 00:00:00 2001 From: Elsa Lossius Date: Mon, 15 Jan 2024 09:38:20 +0100 Subject: [PATCH 5/6] Failing test --- tdd-domain-modelling.CSharp.Main/Basket.cs | 38 +++++++++++++++++++ .../BasketClassTests.cs | 38 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tdd-domain-modelling.CSharp.Main/Basket.cs create mode 100644 tdd-domain-modelling.CSharp.Test/BasketClassTests.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..0061f13 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace td_domain_modelling.CSharp.Main +{ + public class Basket + { + private Dictionary _items = new Dictionary(); + + public Basket() + { + + } + + public bool Add(string product, int price) + { + _items.Add(product, price); + + return _items.Count > 0 ? true : false; + } + + public int Total() + { + throw new NotImplementedException(); + } + + public Dictionary items { get { return _items; } set { _items = value; } } + + + } +} + + + + diff --git a/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs b/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs new file mode 100644 index 0000000..13261e2 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketClassTests.cs @@ -0,0 +1,38 @@ +using NUnit.Framework; +using td_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + public class BasketClassTests + { + [Test] + public void shouldAddProductToBasket() + { + // Setup + Basket b = new Basket(); + + // Execute + bool added = b.Add("Coca cola", 22); + + // Verify + Assert.That(added, Is.True); + Assert.That(b.items != null, Is.True); + } + + [Test] + public void shouldReturnPriceForProductsInBasket() + { + // Setup + Basket b = new Basket(); + b.Add("Coca cola", 22); + b.Add("Urge", 22); + + //Execute + int sum = b.Total(); + + // Verify + Assert.That(sum == 44); + } + } + +} From b6266258e4c1f68db085b2caa5e69c6b3960e616 Mon Sep 17 00:00:00 2001 From: Elsa Lossius Date: Mon, 15 Jan 2024 09:41:08 +0100 Subject: [PATCH 6/6] Green tests --- tdd-domain-modelling.CSharp.Main/Basket.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs index 0061f13..f9c59ac 100644 --- a/tdd-domain-modelling.CSharp.Main/Basket.cs +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -24,7 +24,7 @@ public bool Add(string product, int price) public int Total() { - throw new NotImplementedException(); + return _items.Values.Sum(); } public Dictionary items { get { return _items; } set { _items = value; } }