Skip to content
18 changes: 18 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


| Classes | Methods | Scenario | Outputs |
|----------|-------------------------|------------------------------------------------------------------|---------|
| `Basket` | `addBagel(String bagel` | `If the begal is not already in the basket` | `true` |
| | | `If the bagel is already in the basket` | `false` |
| | | `If the basket is full` | `false` |
| | | | |
| | `removeBagel()` | `Removes the bagel from my basket if the bagel is in the basket` | `True` |
| | | `Removes the bagel from my basket if the bagel is not in basket` | `False` |
| | | | |
| | `Basket(int capacity)` | `Setting the capacity of the basket` | `int` |
| | | | |
| | `CheckDuplicates` | `If bagel is in already in the basket` | `True` |
| | | `If basket is not in the basket` | `False` |
| | | | |
| | `isFull()` | `If the basket is full` | `True` |
| | | `If the basket is not full` | `False` |
47 changes: 47 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
private ArrayList<String> items;
private int capacity;


public Basket(int capacity) {
this.items = new ArrayList<>();
this.capacity = capacity;
}


public boolean isFull() {
return items.size() >=capacity;

}


public boolean addBagel(String bagel){
if (isFull()) {
return false;
}

if (items.contains(bagel)){
return false;
}

items.add(bagel);
return true;
}

public boolean removeBagel(String bagel){
if (items.contains(bagel)) {
items.remove(bagel);
return true;
}

return false;
}


public boolean checkDuplicates(String bagel) {
return items.contains(bagel);
}


}


48 changes: 48 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,54 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

class BasketTest {


@Test
public void testAddBagelToBasketIfNotFull(){
Basket basket = new Basket(10);
Assertions.assertTrue(basket.addBagel("Crispy Bagel"));
}



@Test
public void testAddBagelToBasketIfFull(){
Basket basket = new Basket(1);
basket.addBagel("Plain Bagel");
boolean result = basket.addBagel("Crispy Bagel");
Assertions.assertFalse(result);
}

@Test
public void testRemoveExistingBagelFromBasket() {
Basket basket = new Basket(5);
basket.addBagel("Plain Bagel");
basket.addBagel("Crispy Bagel");
boolean result = basket.removeBagel("Plain Bagel");
Assertions.assertTrue(result);

}

@Test
public void testRemoveNonExistingBagelFromBasket() {
Basket basket = new Basket(5);
basket.addBagel("Plain Bagel");
basket.addBagel("Crispy Bagel");
boolean result = basket.removeBagel("Cheese Bagel");
Assertions.assertFalse(result);

}

@Test
public void testShouldNotAddDuplicateBagel() {
Basket basket = new Basket(10);
basket.addBagel("Plain Bagel");
boolean result = basket.checkDuplicates("Plain Bagel");
Assertions.assertTrue(result);
}


}