From 3deae8a764665ee596e22983abdd171551ce14cf Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 13:26:48 +0200 Subject: [PATCH 01/22] Domain model created with the user stories --- domain-model.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 domain-model.md diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..b2193a98 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,16 @@ +# Domain model + +Assuming that: +- A userType of 0 is a Bob Bagel's manager +- A userType of 1 is the public + +| Classes | Methods | Scenario | Outputs | +|----------|-------------------------------------------------------|------------------------------------------------|---------| +| `Basket` | `add(String bagel, int userType)` | Successfully added to basket | true | +| | | Failed to add to basket (e.g., already exists) | false | +| | `remove(String bagel, int userType)` | Successfully removed from basket | true | +| | | Failed to remove from basket | false | +| | `isFull()` | Basket is full | true | +| | | Basket is not full | false | +| | `changeBasketCapacity(int newCapacity, int userType)` | Successfully changed capacity of baskets | true | +| | | Failed to change capacity of baskets | false | From 46c0303bb71efb7ec3f1d18f69155cb8add63029 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 13:54:06 +0200 Subject: [PATCH 02/22] Changed domain model slightly --- domain-model.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/domain-model.md b/domain-model.md index b2193a98..06e5e4d7 100644 --- a/domain-model.md +++ b/domain-model.md @@ -1,14 +1,15 @@ # Domain model Assuming that: + - A userType of 0 is a Bob Bagel's manager - A userType of 1 is the public | Classes | Methods | Scenario | Outputs | |----------|-------------------------------------------------------|------------------------------------------------|---------| -| `Basket` | `add(String bagel, int userType)` | Successfully added to basket | true | +| `Basket` | `add(String bagel)` | Successfully added to basket | true | | | | Failed to add to basket (e.g., already exists) | false | -| | `remove(String bagel, int userType)` | Successfully removed from basket | true | +| | `remove(String bagel)` | Successfully removed from basket | true | | | | Failed to remove from basket | false | | | `isFull()` | Basket is full | true | | | | Basket is not full | false | From 10583112ab59f5a8f7eb85576c6b0adb624a9da3 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 13:55:59 +0200 Subject: [PATCH 03/22] Added test for adding a bagel to basket --- src/test/java/com/booleanuk/core/BasketTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index e35771b3..1a6e75e7 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -5,4 +5,14 @@ class BasketTest { + public BasketTest() { + + } + + @Test + public void testAddBagel() { + Basket b = new Basket(); + Assertions.assertTrue(b.add("testBagel")); + } + } From 8092e4fa7088bab2dc973ccf9675245a7c097b7a Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:03:48 +0200 Subject: [PATCH 04/22] Added an assumption to domain model --- domain-model.md | 1 + 1 file changed, 1 insertion(+) diff --git a/domain-model.md b/domain-model.md index 06e5e4d7..3dfe4417 100644 --- a/domain-model.md +++ b/domain-model.md @@ -4,6 +4,7 @@ Assuming that: - A userType of 0 is a Bob Bagel's manager - A userType of 1 is the public +- There cannot be two of the same bagels in the same basket | Classes | Methods | Scenario | Outputs | |----------|-------------------------------------------------------|------------------------------------------------|---------| From 9813c3b8e3cb2324aa35952c74b0710112e51b55 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:04:12 +0200 Subject: [PATCH 05/22] Implemented constructor in Basket. Implemented add-method in Basket. --- src/main/java/com/booleanuk/core/Basket.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index df7a20aa..b036987b 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -1,5 +1,25 @@ package com.booleanuk.core; +import java.util.ArrayList; + public class Basket { + private final int DEFAULT_CAPACITY = 10; // Assuming basket has capacity of 10 from beginning + + ArrayList bagels; + private int capacity; + + public Basket() { + this.bagels = new ArrayList<>(); + this.capacity = this.DEFAULT_CAPACITY; + } + + public boolean add(String bagel) { + if (this.bagels.contains(bagel) || this.bagels.size() == this.capacity) { + return false; + } + this.bagels.add(bagel); + return true; + } + } From 285c16c1fe926fd0c03eb08a3279362f02ded3bd Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:06:59 +0200 Subject: [PATCH 06/22] Updated domain model assumption --- domain-model.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain-model.md b/domain-model.md index 3dfe4417..6ff93dab 100644 --- a/domain-model.md +++ b/domain-model.md @@ -4,7 +4,7 @@ Assuming that: - A userType of 0 is a Bob Bagel's manager - A userType of 1 is the public -- There cannot be two of the same bagels in the same basket +- Bagels are unique; there cannot be two or more of the same bagels in the same basket | Classes | Methods | Scenario | Outputs | |----------|-------------------------------------------------------|------------------------------------------------|---------| From c01b6f56fba0c88f76985c31bf2fa88c7aabab84 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:07:25 +0200 Subject: [PATCH 07/22] Added test for removing a bagel from Basket --- src/test/java/com/booleanuk/core/BasketTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index 1a6e75e7..f33914d6 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -15,4 +15,11 @@ public void testAddBagel() { Assertions.assertTrue(b.add("testBagel")); } + @Test + public void testRemoveBagel() { + Basket b = new Basket(); + b.add("test"); + Assertions.assertTrue(b.remove("test")); + } + } From 3175d3c36af910cd045e779608781b324a3a9684 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:09:38 +0200 Subject: [PATCH 08/22] Added test for isFull method --- src/test/java/com/booleanuk/core/BasketTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index f33914d6..7c7d8344 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -22,4 +22,20 @@ public void testRemoveBagel() { Assertions.assertTrue(b.remove("test")); } + @Test + public void testIsBasketFull() { + Basket b = new Basket(); + b.add("test"); + b.add("test2"); + b.add("test3"); + b.add("test4"); + b.add("test5"); + b.add("test6"); + b.add("test7"); + b.add("test8"); + b.add("test9"); + b.add("test10"); + Assertions.assertTrue(b.isFull()); + } + } From dca6e218ad61c486c7e0120af4f26796d196ff57 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:10:03 +0200 Subject: [PATCH 09/22] Added code for removing a bagel --- src/main/java/com/booleanuk/core/Basket.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index b036987b..cd9f9df3 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -22,4 +22,8 @@ public boolean add(String bagel) { return true; } + public boolean remove(String bagel) { + return this.bagels.remove(bagel); + } + } From d0bfb6f03587e0ef5d99551730ebdd7db8f3e5b4 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:11:10 +0200 Subject: [PATCH 10/22] Implemented isFull method in Basket --- src/main/java/com/booleanuk/core/Basket.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index cd9f9df3..9650a161 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -26,4 +26,8 @@ public boolean remove(String bagel) { return this.bagels.remove(bagel); } + public boolean isFull() { + return this.bagels.size() == this.capacity; + } + } From ca2203fb0fcc070926bc98be9167458562e1b411 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:15:18 +0200 Subject: [PATCH 11/22] Changed domain model --- domain-model.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/domain-model.md b/domain-model.md index 6ff93dab..59b05d71 100644 --- a/domain-model.md +++ b/domain-model.md @@ -6,13 +6,12 @@ Assuming that: - A userType of 1 is the public - Bagels are unique; there cannot be two or more of the same bagels in the same basket -| Classes | Methods | Scenario | Outputs | -|----------|-------------------------------------------------------|------------------------------------------------|---------| -| `Basket` | `add(String bagel)` | Successfully added to basket | true | -| | | Failed to add to basket (e.g., already exists) | false | -| | `remove(String bagel)` | Successfully removed from basket | true | -| | | Failed to remove from basket | false | -| | `isFull()` | Basket is full | true | -| | | Basket is not full | false | -| | `changeBasketCapacity(int newCapacity, int userType)` | Successfully changed capacity of baskets | true | -| | | Failed to change capacity of baskets | false | +| Classes | Methods | Scenario | Outputs | +|----------|-------------------------------------------------|------------------------------------------------|---------| +| `Basket` | `add(String bagel)` | Successfully added to basket | true | +| | | Failed to add to basket (e.g., already exists) | false | +| | `remove(String bagel)` | Successfully removed from basket | true | +| | | Failed to remove from basket | false | +| | `isFull()` | Basket is full | true | +| | | Basket is not full | false | +| | `changeCapacity(int newCapacity, int userType)` | Changing th Basket's capacity | - | From 4426a6950bc7c0ab55047fbf644021a7c27b4c4d Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:15:34 +0200 Subject: [PATCH 12/22] Added test for changing the capacity of a Basket --- .../java/com/booleanuk/core/BasketTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index 7c7d8344..3b23024b 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -38,4 +38,25 @@ public void testIsBasketFull() { Assertions.assertTrue(b.isFull()); } + @Test + public void testChangeCapacity() { + Basket b = new Basket(); + b.add("test"); + b.add("test2"); + b.add("test3"); + b.add("test4"); + b.add("test5"); + b.add("test6"); + b.add("test7"); + b.add("test8"); + b.add("test9"); + b.add("test10"); + + Assertions.assertTrue(b.isFull()); + + b.changeCapacity(11, 0); + + Assertions.assertFalse(b.isFull()); + } + } From cd53f9fec06d5380d8e1e2a2d0ea5cd80663f75d Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:16:27 +0200 Subject: [PATCH 13/22] Implemented functionality to change a Basket's capacity --- src/main/java/com/booleanuk/core/Basket.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index 9650a161..0eeffaaa 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -30,4 +30,8 @@ public boolean isFull() { return this.bagels.size() == this.capacity; } + public void changeCapacity(int newCapcity, int userType) { + this.capacity = newCapcity; + } + } From 14d1347243398a53f38f6620f6e31bd4d4903486 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:19:09 +0200 Subject: [PATCH 14/22] Revert domain model to previous --- domain-model.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/domain-model.md b/domain-model.md index 59b05d71..0c30d40c 100644 --- a/domain-model.md +++ b/domain-model.md @@ -14,4 +14,5 @@ Assuming that: | | | Failed to remove from basket | false | | | `isFull()` | Basket is full | true | | | | Basket is not full | false | -| | `changeCapacity(int newCapacity, int userType)` | Changing th Basket's capacity | - | +| | `changeCapacity(int newCapacity, int userType)` | Successfully changed capacity of baskets | true | +| | | Failed to change capacity of baskets | false | From 551be9f63e06fb25b25e5c9cf8cfe5abc046895f Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:20:49 +0200 Subject: [PATCH 15/22] Added test for checking negative capacity input --- src/test/java/com/booleanuk/core/BasketTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index 3b23024b..ff4d3af9 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -59,4 +59,11 @@ public void testChangeCapacity() { Assertions.assertFalse(b.isFull()); } + @Test + public void testChangeCapacityInputNotNegative() { + Basket b = new Basket(); + + Assertions.assertFalse(b.changeCapacity(-1, 0)); + } + } From fdcc207f5c1b9be2f09733ee258ac343ea2d6794 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:22:26 +0200 Subject: [PATCH 16/22] Checking for negativ value input in changeCapacity method in Basket --- src/main/java/com/booleanuk/core/Basket.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index 0eeffaaa..23c2ee6e 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -30,8 +30,11 @@ public boolean isFull() { return this.bagels.size() == this.capacity; } - public void changeCapacity(int newCapcity, int userType) { + public boolean changeCapacity(int newCapcity, int userType) { + if (newCapcity < 0) return false; + this.capacity = newCapcity; + return true; } } From e151310d800ab51175cd068734b6a82c7ff4f2a7 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:22:52 +0200 Subject: [PATCH 17/22] Added test to check if given new capacity is less than the number of bagels in the Basket --- src/test/java/com/booleanuk/core/BasketTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index ff4d3af9..ea1d2096 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -66,4 +66,14 @@ public void testChangeCapacityInputNotNegative() { Assertions.assertFalse(b.changeCapacity(-1, 0)); } + @Test + public void testChangeCapacityNotLessThanBagelsInBasket() { + Basket b = new Basket(); + + b.add("test"); + b.add("test2"); + + Assertions.assertFalse(b.changeCapacity(1, 1)); + } + } From ad4755f1b6fdd340375e0c71b165a0c23b5ac939 Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:24:38 +0200 Subject: [PATCH 18/22] Implemented check for if given new capacity is less than the number of bagels in the Basket --- src/main/java/com/booleanuk/core/Basket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index 23c2ee6e..85d86b72 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -31,7 +31,7 @@ public boolean isFull() { } public boolean changeCapacity(int newCapcity, int userType) { - if (newCapcity < 0) return false; + if (newCapcity < 0 || newCapcity < this.bagels.size()) return false; this.capacity = newCapcity; return true; From 0dd1e941b5f220995e5146cb307ad8f3cd2d53fd Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:26:06 +0200 Subject: [PATCH 19/22] Added test to check so that the public cannot change the Basket capacity, i.e. only the managers should be able to --- src/test/java/com/booleanuk/core/BasketTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index ea1d2096..2d60a82d 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -76,4 +76,11 @@ public void testChangeCapacityNotLessThanBagelsInBasket() { Assertions.assertFalse(b.changeCapacity(1, 1)); } + @Test + public void testPublicCannotChangeBasketCapacity() { + Basket b = new Basket(); + + Assertions.assertFalse(b.changeCapacity(20, 0)); + } + } From 8b4154d29000092c813edd329410c6e5696d0c9a Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:27:18 +0200 Subject: [PATCH 20/22] Added code to check so that only Bob Bagel's managers can change the Basket capacity --- src/main/java/com/booleanuk/core/Basket.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index 85d86b72..b1428093 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -31,7 +31,7 @@ public boolean isFull() { } public boolean changeCapacity(int newCapcity, int userType) { - if (newCapcity < 0 || newCapcity < this.bagels.size()) return false; + if (newCapcity < 0 || newCapcity < this.bagels.size() || userType != 1) return false; this.capacity = newCapcity; return true; From b8429cc86bb084d6eed06448da4f880cfba2adac Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:35:59 +0200 Subject: [PATCH 21/22] Added test for checking if removing a non-existant bagel is not possible (test passed without new code) --- src/test/java/com/booleanuk/core/BasketTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index 2d60a82d..b000801c 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -22,6 +22,13 @@ public void testRemoveBagel() { Assertions.assertTrue(b.remove("test")); } + @Test + public void testRemoveBagelNotExisting() { + Basket b = new Basket(); + + Assertions.assertFalse(b.remove("test")); + } + @Test public void testIsBasketFull() { Basket b = new Basket(); From 64fb422cd689acc2f40a2da21baea840636f06bc Mon Sep 17 00:00:00 2001 From: Max V Olofsson Date: Wed, 14 Aug 2024 14:42:28 +0200 Subject: [PATCH 22/22] One test failed, fixed itt --- domain-model.md | 2 +- src/main/java/com/booleanuk/core/Basket.java | 2 +- src/test/java/com/booleanuk/core/BasketTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/domain-model.md b/domain-model.md index 0c30d40c..047c7981 100644 --- a/domain-model.md +++ b/domain-model.md @@ -3,7 +3,7 @@ Assuming that: - A userType of 0 is a Bob Bagel's manager -- A userType of 1 is the public + - A userType of 1 is the public - Bagels are unique; there cannot be two or more of the same bagels in the same basket | Classes | Methods | Scenario | Outputs | diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index b1428093..c23d503b 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -31,7 +31,7 @@ public boolean isFull() { } public boolean changeCapacity(int newCapcity, int userType) { - if (newCapcity < 0 || newCapcity < this.bagels.size() || userType != 1) return false; + if (newCapcity < 0 || newCapcity < this.bagels.size() || userType != 0) return false; this.capacity = newCapcity; return true; diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index b000801c..753c1b52 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -87,7 +87,7 @@ public void testChangeCapacityNotLessThanBagelsInBasket() { public void testPublicCannotChangeBasketCapacity() { Basket b = new Basket(); - Assertions.assertFalse(b.changeCapacity(20, 0)); + Assertions.assertFalse(b.changeCapacity(20, 1)); } }