Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
#Domain Models In Here
#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<Cohort> 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<string, int> 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<string, int> basket` | get receipt | (dictionary, int, int) |
30 changes: 30 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -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<string, int> items = new Dictionary<string, int>();

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;
}
}
}
4 changes: 4 additions & 0 deletions tdd-domain-modelling.CSharp.Main/CohortManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ namespace tdd_domain_modelling.CSharp.Main
{
public class CohortManager
{
public bool search(List<string> cohorts, string name)
{
return cohorts.Contains(name);
}
}
}
9 changes: 9 additions & 0 deletions tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public class CohortManagerTest
public void FirstTest()
{
CohortManager core = new CohortManager();
List<string> 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);
}
}
}
40 changes: 40 additions & 0 deletions tdd-domain-modelling.CSharp.Test/SupermarketTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}