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
21 changes: 20 additions & 1 deletion domain-model.md
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
#Domain Models In Here
# Domain Models In Here

### User story 1
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 | Outputs |
|---------|--------------|---------------|
| Basket | totalCost() | int sum |

### User story 2
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 | Outputs |
|---------|-----------|----------------|
| Basket | receipt() | string receipt |
39 changes: 39 additions & 0 deletions tdd-domain-modelling.CSharp.Main/Basket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@


using System.Diagnostics.CodeAnalysis;

namespace tdd_domain_modelling.CSharp.Main
{
public class Basket
{
Dictionary<string, int> items = new Dictionary<string, int>();

public bool add(string item, int price)
{
if (items.ContainsKey(item))
{
return false;
}
else
{
items.Add(item, price);
return true;
}
}

public int total()
{
int totalSum = 0;

foreach( int price in items.Values)
{

totalSum += price;

}

return totalSum;
}

}
}
64 changes: 64 additions & 0 deletions tdd-domain-modelling.CSharp.Test/BasketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Diagnostics.CodeAnalysis;
using NUnit.Framework;
using tdd_domain_modelling.CSharp.Main;

//based tests on the domain model provided in exercice2.md
namespace tdd_domain_modelling.CSharp.Test
{
[TestFixture]
public class BasketTest
{
[Test]
public void addItemforFirstTimeTest()
{
Basket b = new Basket();

bool added = b.add("apple", 10);

Assert.That(added);
}

[Test]
public void addItemAlreadyInBasketTest()
{
Basket b = new Basket();

b.add("apple", 10);
bool added = b.add("apple", 10);

Assert.That(!added);

}

[Test]
public void totalSumTest1()
{
Basket b = new Basket();
int expected = 70;

b.add("apple", 10);
b.add("coco pops", 40);
b.add("baking soda", 20);

int totalSum = b.total();

Assert.That(totalSum == expected);
}

[Test]
public void totalSumTest2()
{
Basket b = new Basket();
int expected = 70;

b.add("apple", 10);
b.add("coco pops", 40);
b.add("coco pops", 40);
b.add("baking soda", 20);

int totalSum = b.total();

Assert.AreEqual(totalSum, expected);
}
}
}
2 changes: 1 addition & 1 deletion tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class CohortManagerTest
[Test]
public void FirstTest()
{
CohortManager core = new CohortManager();

}
}
}