From 240888b5c10a02ea00a84ae5783f279eae767c9c Mon Sep 17 00:00:00 2001 From: Aleksander Kolsrud Date: Mon, 15 Jan 2024 12:00:33 +0100 Subject: [PATCH 1/2] Aleksander Kolsrud C#ex3 --- domain-model.md | 45 ++++++++++++- exercise1.md | 4 +- tdd-domain-modelling.CSharp.Main/Basket.cs | 42 ++++++++++++ .../BasketTest.cs | 66 +++++++++++++++++++ .../CohortManagerTests.cs | 7 ++ 5 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 tdd-domain-modelling.CSharp.Main/Basket.cs create mode 100644 tdd-domain-modelling.CSharp.Test/BasketTest.cs diff --git a/domain-model.md b/domain-model.md index 653f474..a616dd8 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1 +1,44 @@ -#Domain Models In Here \ No newline at end of file +#Domain Models In Here +``` +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: +`Basket` + +Methods: +`BasketTotal()` Summarize the total of all items in basket. +`CalculateSum()` + +Scenario: +1. If basket is empty +2. If basket contains products + +Output: +1. Output 0 +2. Output totalprice + + +``` +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: +`Basket` Create a basket to hold products + +Methods: +`BasketTotal()` Summarize the total of products +`PrintReceipt()` Print a receipt of items + quantity, and totalprice. + +Scenario: +1. If basket is empty +2. If basket contains products + +Output: +1. Output 0 +2. Output totalprice \ No newline at end of file diff --git a/exercise1.md b/exercise1.md index 35588dd..972396b 100644 --- a/exercise1.md +++ b/exercise1.md @@ -37,7 +37,9 @@ 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. ``` -``` + + +``` 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 diff --git a/tdd-domain-modelling.CSharp.Main/Basket.cs b/tdd-domain-modelling.CSharp.Main/Basket.cs new file mode 100644 index 0000000..c5d03ba --- /dev/null +++ b/tdd-domain-modelling.CSharp.Main/Basket.cs @@ -0,0 +1,42 @@ +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 + { + private Dictionary _basket = new Dictionary(); + + public Dictionary Add(string item, int price) + { + if (_basket.ContainsKey(item)) + { + return _basket; + } + else + { + _basket.Add(item, price); + } + return _basket; + } + public int sum() + { + int totalSum = 0; + foreach (var item in _basket) + { + totalSum += item.Value; + } + return totalSum; + } + + + + + + } + +} + diff --git a/tdd-domain-modelling.CSharp.Test/BasketTest.cs b/tdd-domain-modelling.CSharp.Test/BasketTest.cs new file mode 100644 index 0000000..d39a0f6 --- /dev/null +++ b/tdd-domain-modelling.CSharp.Test/BasketTest.cs @@ -0,0 +1,66 @@ +using NUnit.Framework; +using tdd_domain_modelling.csharp.main; +using tdd_domain_modelling.CSharp.Main; + + + +namespace tdd_domain_modelling.csharp.test +{ + public class BasketTests + { + [Test] + public void FirstTest() + { + + Basket basket = new Basket(); + } + + + [TestCase("banana", 10)] + [TestCase("Pineapple", 5)] + public void Add(string item, int price) + { + //arrange + Basket basket = new Basket(); + + //act + Dictionary _basket = basket.Add(item, price); + + //assert + Assert.IsTrue(_basket.ContainsKey(item)); + } + + [TestCase("apple", 10)] + [TestCase("Orange", 5)] + public void BooleanAddTest(string item, int price) + { + //arrange + Basket basket = new Basket(); + + //act + Dictionary items = basket.Add(item, price); + + //assert + Assert.IsTrue(items.ContainsKey(item)); + } + + [Test] + public void total() + { + //arrange + Basket basket = new Basket(); + basket.Add("apple", 10); + basket.Add("bana", 5); + //act + int result = basket.sum(); + + //assert + Assert.IsTrue(result == 15); + } + + + + + } +} + diff --git a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs index 56f3873..ba0865e 100644 --- a/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs +++ b/tdd-domain-modelling.CSharp.Test/CohortManagerTests.cs @@ -9,7 +9,14 @@ public class CohortManagerTest [Test] public void FirstTest() { + //arrange CohortManager core = new CohortManager(); + + //act + + + //assert + } } } \ No newline at end of file From df9a0db81101787831b27c74e8be7325de721666 Mon Sep 17 00:00:00 2001 From: Aleksander Kolsrud Date: Mon, 15 Jan 2024 12:00:59 +0100 Subject: [PATCH 2/2] Aleksander Kolsrud C#ex3 --- tdd-domain-modelling.CSharp.Test/BasketTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tdd-domain-modelling.CSharp.Test/BasketTest.cs b/tdd-domain-modelling.CSharp.Test/BasketTest.cs index d39a0f6..debacdb 100644 --- a/tdd-domain-modelling.CSharp.Test/BasketTest.cs +++ b/tdd-domain-modelling.CSharp.Test/BasketTest.cs @@ -30,8 +30,8 @@ public void Add(string item, int price) Assert.IsTrue(_basket.ContainsKey(item)); } - [TestCase("apple", 10)] - [TestCase("Orange", 5)] + [TestCase("orange juice", 10)] + [TestCase("oat milk", 20)] public void BooleanAddTest(string item, int price) { //arrange @@ -50,7 +50,7 @@ public void total() //arrange Basket basket = new Basket(); basket.Add("apple", 10); - basket.Add("bana", 5); + basket.Add("banana", 5); //act int result = basket.sum();