diff --git a/domain-model.md b/domain-model.md index 653f474..02827d9 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,45 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here + +## Analyse +The developer made an assumption that the user wants to simply know if the name is in the list or not. +They are also assuming that cohort is just stored as a string within the system, but it could also be stored as a Class. +When reading the user story, it would in my eyes be more plausible that the user wanted to find a specific cohort +in the list of all cohorts, maybe to find out more information about them just based on the name. + +As it would not make sense for a search function to simply say that the cohort exists or not, +I would instead just return the cohort as a Class, like this: + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `CohortManager` | `search(List cohorts, String name)` | If name is in list | cohort | +| | | If name is not in list | null | + +## Exercise +``` +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. +``` + +Without knowing much of how the supermarket checkout application is developed, we do not know if we should +be passing an argument or not. We are missing a lot of knowledge about how the solution is built. + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------------|---------| +| `Checkout` | `showSum(Dictionary basket)` | Showing sum of products| int | + +``` +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. +``` + +Here we want to output a receipt that includes a list of the products with their name and price. +We also want to output the total number of products, as well the total cost of the products. +As a very simple case, we can just store all this information within a tuple; + + +| Classes | Methods | Scenario | Outputs | +|-----------------|---------------------------------------------|------------------|------------------------| +| `ReceiptPrinter`| `getReceipt(Dictionary basket` | get receipt | (dictionary, int, int) | \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..076aa84 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace tdd_domain_modelling.CSharp.Main +{ + public class Basket + { + Dictionary items = new Dictionary(); + + public bool add(string product, int price) + { + if (items.ContainsKey(product)) return false; + items.Add(product, price); + return true; + } + + public int total() + { + int sum = 0; + foreach (var item in items) + { + sum += item.Value; + } + return sum; + } + } +} diff --git a/tdd-domain-modelling.CSharp.Main/CohortManager.cs b/tdd-domain-modelling.CSharp.Main/CohortManager.cs index 6a5669c..eb5e652 100644 --- a/tdd-domain-modelling.CSharp.Main/CohortManager.cs +++ b/tdd-domain-modelling.CSharp.Main/CohortManager.cs @@ -8,5 +8,9 @@ namespace tdd_domain_modelling.CSharp.Main { public class CohortManager { + public bool search(List cohorts, string name) + { + return cohorts.Contains(name); + } } } diff --git a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs index 56f3873..0f3cbfd 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -10,6 +10,15 @@ public class CohortManagerTest public void FirstTest() { CohortManager core = new CohortManager(); + List cohorts = ["Ole", "Dole", "Doffen"]; + string name = "Ole"; + string name2 = "Donald"; + + bool test1 = core.search(cohorts, name); + bool test2 = core.search(cohorts, name2); + + Assert.That(test1 == true); + Assert.That(test2 == false); } } } \ No newline at end of file diff --git a/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs new file mode 100644 index 0000000..04bbe1a --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/SupermarketTests.cs @@ -0,0 +1,40 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using tdd_domain_modelling.CSharp.Main; + +namespace tdd_domain_modelling.CSharp.Test +{ + public class SupermarketTests + { + [TestCase("Milk", 15)] + public void BasketTrueTest(String product, int price) + { + Basket basket = new Basket(); + bool added = basket.add(product, price); + Assert.That(added == true); + } + + [TestCase("Bread", 10)] + public void BasketFalseTest(String product, int price) + { + Basket basket = new Basket(); + basket.add(product, price); + bool added = basket.add(product, price); + Assert.That(added == false); + } + + [Test] + public void TotalCostTest() + { + Basket basket = new Basket(); + basket.add("Bread", 10); + basket.add("Milk", 15); + int total = basket.total(); + Assert.That(total == 25); + } + } +}