diff --git a/domain-model.md b/domain-model.md new file mode 100644 index 00000000..5517b7e1 --- /dev/null +++ b/domain-model.md @@ -0,0 +1,8 @@ + +| Classes | Methods | Scenario | Outputs | +|----------|-----------------------------|--------------------------------|---------| +| `Basket` | `AddBagel(String bagel)` | Add bagel | bool | +| | `RemoveBagel(String bagel)` | Remove bagel | bool | +| | `IsFull()` | Check capacity | bool | +| | `SetCapacity(int capacity)` | Change capacity | | +| | `RemoveBagel()` | Remove a bagel that dont exist | int | \ No newline at end of file diff --git a/src/main/java/com/booleanuk/core/Basket.java b/src/main/java/com/booleanuk/core/Basket.java index df7a20aa..bd8c4773 100644 --- a/src/main/java/com/booleanuk/core/Basket.java +++ b/src/main/java/com/booleanuk/core/Basket.java @@ -1,5 +1,63 @@ +//Basket.java package com.booleanuk.core; +import java.util.ArrayList; + public class Basket { + public ArrayList baskets; + private int capacity; + + public Basket() { + + this.baskets = new ArrayList<>(); + this.capacity = 2; + + } + + public boolean add(String bagel) { + + if (this.baskets.size() < this.capacity) { + + return this.baskets.add(bagel); + + } + + return false; + } + + public boolean remove(String bagel) { + + return this.baskets.remove(bagel); + + } + + public boolean IsFull() { + + return this.baskets.size() >= this.capacity; + + } + + public void setCapacity(int capacity) { + + if (capacity > 0) { + + this.capacity = capacity; + + } + } + + public int removeBagel(String bagel) { + + if (this.baskets.contains(bagel)) { + + this.baskets.remove(bagel); + return 1; + + } else { + + return -1; + + } + } } diff --git a/src/test/java/com/booleanuk/core/BasketTest.java b/src/test/java/com/booleanuk/core/BasketTest.java index e35771b3..17477841 100644 --- a/src/test/java/com/booleanuk/core/BasketTest.java +++ b/src/test/java/com/booleanuk/core/BasketTest.java @@ -1,8 +1,66 @@ +// BasketTest.java package com.booleanuk.core; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; + class BasketTest { -} + ArrayList baskets; + + @Test + public void testAddBagel() { + + Basket basket = new Basket(); + Assertions.assertTrue(basket.add("bagel1")); + + } + + @Test + public void testRemoveBagel() { + + Basket basket = new Basket(); + basket.add("bagel1"); + + Assertions.assertTrue(basket.remove("bagel1")); + + } + + @Test + public void testIsFull() { + + Basket basket = new Basket(); + + Assertions.assertTrue(basket.add("bagel1")); + Assertions.assertTrue(basket.add("bagel2")); + + Assertions.assertTrue(basket.IsFull()); + + } + + @Test + public void testSetCapacity() { + Basket basket = new Basket(); + + Assertions.assertTrue(basket.add("bagel1")); + Assertions.assertTrue(basket.add("bagel2")); + Assertions.assertFalse(basket.add("bagel3")); + + basket.setCapacity(3); + + Assertions.assertTrue(basket.add("bagel3")); + + } + + @Test + public void removeBagel() { + Basket basket = new Basket(); + + basket.add("bagel1"); + + Assertions.assertEquals(1, basket.removeBagel("bagel1")); + Assertions.assertEquals(-1, basket.removeBagel("bagel2")); + } +} \ No newline at end of file