diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..030e4ce1 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,16 @@ + +| Classes | Variables | Methods | Scenario | Outcomes | +|----------|----------------------------------------------|-----------------------------|------------------------------------------------------|---------------------------------------------------------------------------| +| `Basket` | `private List basket` | `add(String bagel)` | Bagel is in the bagel list and the basket is not ful | Add bagel to basket, increment the currentBasketCapacity and return true | +| | `private List bagels` | | Bagel is not the list | Return false | +| | | | Basket is ful | Return false | +| | | | | | +| | `private int maxBasketCapacity` | `isBasketFull()` | Basket is ful | Write message to console and return true | +| | `private final int SIZE_TO_INCREMENT_BASKET` | | Basket is not ful | Return false | +| | | | | | +| | | `remove(String bagel)` | Bagel is in the bagel list | Remove bagel from basket, decrement currentBasketCapacity and return true | +| | | | Bagel is not in the basket | Write rejection message to console and return false | +| | | | | | +| | | | | | +| | | `ìncrementBasketCapacity()` | Increment the basket capacity | Write confirmation message to console | +| | | | | | diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index df7a20aa..d27c2d49 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -1,5 +1,53 @@ package com.booleanuk.core; +import java.util.ArrayList; +import java.util.List; + public class Basket { + private final List bagels; + private final List basket; + + private int maxBasketCapacity = 5; + private static final int SIZE_TO_INCREMENT_BASKET = 5; + + public Basket() { + this.bagels = List.of("bagel1", "bagel2", "bagel3", "bagel4"); + this.basket = new ArrayList<>(); + } + + public boolean addItem(String item) { + if (item.isEmpty() || !bagels.contains(item)) { + return false; + } + basket.add(item); + return true; + } + + public boolean removeItem(String item) { + if (item.isEmpty() || !basket.contains(item)) { + System.out.println("Bagel is not in the basket"); + return false; + } + basket.remove(item); + return true; + } + + public boolean isBasketFull() { + if (basket.size() == maxBasketCapacity) { + System.out.println("Basket is full"); + return true; + } + return false; + } + + public void incrementBasketCapacity() { + System.out.println("Basket capacity increased"); + maxBasketCapacity += SIZE_TO_INCREMENT_BASKET; + } + + public List getBasket() { + return basket; + } + } diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index e35771b3..e9db9978 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -5,4 +5,41 @@ class BasketTest { -} + private final Basket basket = new Basket(); + + private void addBagelsToBasket(String... bagels) { + for (String bagel : bagels) { + basket.addItem(bagel); + } + } + + @Test + void testAddItem() { + Assertions.assertFalse(basket.addItem("")); + Assertions.assertTrue(basket.addItem("bagel1")); + Assertions.assertFalse(basket.addItem("bagelThatNotExists")); + Assertions.assertTrue(basket.addItem("bagel4")); + Assertions.assertTrue(basket.getBasket().contains("bagel4")); + } + + @Test + void testRemoveItem() { + Assertions.assertFalse(basket.removeItem("")); + addBagelsToBasket("bagel1"); + Assertions.assertTrue(basket.removeItem("bagel1")); + Assertions.assertFalse(basket.removeItem("bagel1")); + Assertions.assertFalse(basket.getBasket().contains("bagel1")); + } + + @Test + void testIsBasketFull() { + Assertions.assertFalse(basket.isBasketFull()); + addBagelsToBasket("bagel1", "bagel2", "bagel3", "bagel4", "bagel4"); + Assertions.assertTrue(basket.isBasketFull()); + } + + @Test + void testIncrementBasketCapacity() { + basket.incrementBasketCapacity(); + } +} \ No newline at end of file