Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
51e691b
First test
SimpFred Aug 14, 2024
2225a82
First blood on addItem()
SimpFred Aug 14, 2024
d981f94
Second test fails
SimpFred Aug 14, 2024
5793b42
Second test works
SimpFred Aug 14, 2024
99b3e36
Refactored second and third test
SimpFred Aug 14, 2024
12315f4
Third test works
SimpFred Aug 14, 2024
6ebe98a
Added fourth Test
SimpFred Aug 14, 2024
4b2e6eb
Fourth Test works
SimpFred Aug 14, 2024
d016ebd
Added first test for removeItem()
SimpFred Aug 14, 2024
572ecbc
First test on remove pass
SimpFred Aug 14, 2024
42702bf
Second test on removeItem()
SimpFred Aug 14, 2024
c7adc5c
Second test on removeItem() pass
SimpFred Aug 14, 2024
3d9e5fc
Third test on removeItem()
SimpFred Aug 14, 2024
c0cbb71
Third test on removeItem() pass
SimpFred Aug 14, 2024
d876841
Refactored Basket
SimpFred Aug 14, 2024
4d466aa
Refactored third test on removeItem() and refactored Basket again
SimpFred Aug 14, 2024
5897f08
Third test on removeItem()
SimpFred Aug 14, 2024
f8c3a27
Third test on removeItem() pass
SimpFred Aug 14, 2024
2ee738c
Refactored domain model
SimpFred Aug 14, 2024
c555be2
Refactored Basket to follow domain model
SimpFred Aug 14, 2024
dfbb435
First test of isBasketFull()
SimpFred Aug 14, 2024
11933d2
First test of isBasketFull() pass
SimpFred Aug 14, 2024
fa3a5a2
Second test of isBasketFull()
SimpFred Aug 14, 2024
7967e7a
Refactored second test of isBasketFull()
SimpFred Aug 14, 2024
646cc8a
Second test of isBasketFull() pass
SimpFred Aug 14, 2024
c3101f5
Refactored isBasketFull()
SimpFred Aug 14, 2024
7dc51ef
first testIncrementBasketCapacity()
SimpFred Aug 14, 2024
0ad0a1e
First testIncrementBasketCapacity() pass + some refactoring
SimpFred Aug 14, 2024
47c0442
Refactored
SimpFred Aug 14, 2024
1bd5d7c
Refactored the test class to have a addBagelsToBasket method
SimpFred Aug 14, 2024
7bf205c
Refactor
SimpFred Aug 14, 2024
dd5e572
Added one more test to testAddItem()
SimpFred Aug 14, 2024
c754ae9
refactored the test
SimpFred Aug 14, 2024
9f6cf34
The test passes
SimpFred Aug 14, 2024
93e586b
Added a test to testRemoveItem() for better coverage
SimpFred Aug 14, 2024
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
16 changes: 16 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

| Classes | Variables | Methods | Scenario | Outcomes |
|----------|----------------------------------------------|-----------------------------|------------------------------------------------------|---------------------------------------------------------------------------|
| `Basket` | `private List<String> 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<String> 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 |
| | | | | |
48 changes: 48 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class Basket {

private final List<String> bagels;
private final List<String> 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<String> getBasket() {
return basket;
}

}
39 changes: 38 additions & 1 deletion src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}