Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {

ArrayList<String> basket;
int maxCapBasket;

public Basket() {
this.basket = new ArrayList<>();
this.maxCapBasket = 6;
}

public boolean add(String product) {
if (checkBasket() >= maxCapBasket) {
return false;
}
basket.add(product);
return basket.contains(product);
}

public boolean remove(String product) {
basket.remove(product);
return basket.contains(product);
}

public boolean changeCapBasket(int currentCapBasket, int newCapBasket) {
if (currentCapBasket == 0) {
this.maxCapBasket = newCapBasket;
return true;
}
else {
return false;
}
}

public int checkBasket() {
return basket.size();
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/booleanuk/core/design-domain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
| Classes | Variables | Methods | Scenario | Outcome |
|----------|------------------------------------------|--------------------------------------|--------------------------------|------------------|
| `Basket` | `ArrayList<String> products` | `add (String)` | Product will be added | true |
| | | | Product will not be added | false |
| | | | If the basket is full | Error |
| | | `remove (String)` | Product will be removed | true |
| | | | Product will not be removed | false |
| | | | If a product does not exist | Error |
| | | `checkBasket()` | If basket has products | Amount of bagels |
| | | | If basket is full | return 0 |
| | `int maxCapBasket, int currentCapBasket` | `changeCapBasket (int newCapBasket)` | If newCapBasket is more than 0 | true |
| | | | If newCapBasket is less than 1 | false |
| | | | | |
47 changes: 47 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,51 @@

class BasketTest {

@Test
public void addBagelTest() {
Basket basket = new Basket();
Assertions.assertTrue(basket.add("Plane"));
}

@Test
public void removeBagelTest() {
Basket basket = new Basket();
basket.add("Sesame");
Assertions.assertFalse(basket.remove("Nutella"));
}

@Test
public void changeCapBasketTest() {
Basket basket = new Basket();
Assertions.assertTrue(basket.changeCapBasket(0, 6));
Assertions.assertFalse(basket.changeCapBasket(1, 1));
}

@Test
public void checkBasketTest() {
Basket basket = new Basket();
Assertions.assertEquals(0, basket.checkBasket());
for (int i = 0; i < 7; i++) {
basket.add("Sesame");
}
Assertions.assertEquals(6, basket.checkBasket());
}

// Try remove bagel that does not exist
@Test
public void tryRemoveBagelThatDoesNotExistTest() {
Basket basket = new Basket();
basket.add("Plane");
basket.add("Sesame");
Assertions.assertFalse(basket.remove("Nutella"));
}

@Test
public void basketIsFullTest() {
Basket basket = new Basket();
for (int i = 0; i < 7; i++) {
basket.add("Sesame");
}
Assertions.assertFalse(basket.add("Plane"));
}
}