Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a99cbae
domain model
giarreh Jan 15, 2024
2384ed1
Added test for Add bagel
giarreh Jan 15, 2024
c62193f
Wrote code for the addBagel test
giarreh Jan 15, 2024
78904fe
Added more tests for add() to check for empty strings
giarreh Jan 15, 2024
019a7dc
Added more tests for add() to check for empty strings
giarreh Jan 15, 2024
8846e0e
Added removeBagel tests
giarreh Jan 15, 2024
4b7a84d
Added code for removeBagel tests
giarreh Jan 15, 2024
1dcb0bb
Added tests for checking if basket is above capacity, and if basket i…
giarreh Jan 15, 2024
f2c841e
Simplified 3rd user story
giarreh Jan 15, 2024
0d217d7
Simplified 3rd user story
giarreh Jan 15, 2024
02b08f4
Simplified 3rd user story
giarreh Jan 15, 2024
aebc039
Created test for AddBagelIfBasketIsFull
giarreh Jan 15, 2024
e7550f0
Modified test case
giarreh Jan 15, 2024
2120930
Wrote code for testAddBagelIfBasketIsFull
giarreh Jan 15, 2024
a99f73e
Added tests for checking capacity and changed checkIfFull to checkIfN…
giarreh Jan 15, 2024
e4ff9a3
Added tests for checking capacity and changed checkIfFull to checkIfN…
giarreh Jan 15, 2024
21003d3
Added more to ChangeCapacityTest
giarreh Jan 15, 2024
1af675a
Wrote code for changeCapacity & refactored other tests
giarreh Jan 15, 2024
b986b6f
Modified userStory to be more correct on 5.
giarreh Jan 15, 2024
1ff4c45
Wrote tests for TryRemoveBagelInList
giarreh Jan 15, 2024
458d85f
Splitted tests as one was testing two methods
giarreh Jan 15, 2024
5626da4
Wrote code for tryRemoveBagel and modified remove function
giarreh Jan 15, 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
64 changes: 64 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {

ArrayList<String> basket;
public int capacity;

public Basket(){
this.basket = new ArrayList<>();
this.capacity = 5;
}

public boolean checkIfNotFull(){
if(this.basket == null){
return false;
}
if(this.basket.size() > this.capacity){
System.out.println("Basket is full, unable to add bagel!");
return false;
}
System.out.println("Basket is not full, adding bagel");
return true;
}

public String tryRemoveBagel(String bagel){
if (!this.basket.contains(bagel)) {
System.out.println("Bagel not in list");
return "Bagel not in list";
}
System.out.println("Bagel is removed from list");
this.basket.remove(bagel);
return "Bagel is removed from list";
}
public int changeCapacity(int capacity){
if(capacity < 0 ){
System.out.println("Invalid capacity, setting default capacity of 5");
return this.capacity = 5;
}
return this.capacity = capacity;
}
public boolean remove(String bagel) {
if(bagel == null){
return false;
}
if(!this.basket.contains(bagel)){
return false;
}
this.tryRemoveBagel(bagel);
return true;
}



public boolean add(String bagel){
if(bagel == null){
return false;
}
if(bagel.isEmpty()){
return false;
}
if(checkIfNotFull()){
basket.add(bagel);
}
return true;
}

}
85 changes: 85 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,89 @@

class BasketTest {

// ADD BAGELS TEST
@Test
public void testAddBagelToBasketReturnTrue(){
Basket basket = new Basket();
boolean result = basket.add("chocolate");
Assertions.assertTrue(result);
}

@Test
public void testAddBagelToBasketWithTrueAndFalse(){
Basket basket = new Basket();
Assertions.assertTrue(basket.add("vanilla"));
Assertions.assertTrue(basket.add("chocolate"));
Assertions.assertFalse(basket.add(""));
}

// REMOVE BAGEL TESTS
@Test
public void testRemoveBagelFromBasketReturnsTrue(){
Basket basket = new Basket();

basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
basket.add("Blueberry");

Assertions.assertTrue(basket.remove("Chocolate"));
Assertions.assertFalse(basket.remove("Plain"));
Assertions.assertTrue(basket.remove("Cookie Dough"));
}

@Test
public void testChangeCapacityOfBasket(){
Basket basket = new Basket();
Assertions.assertEquals(5, basket.capacity);
basket.changeCapacity(10);
Assertions.assertEquals(10, basket.capacity);
basket.changeCapacity(-3);
Assertions.assertEquals(5, basket.capacity);
}

@Test
public void testBasketIsFullAfterCapacityChange(){
Basket basket = new Basket();
basket.changeCapacity(10);
for (int i = 0; i < 8; i++) {
basket.add("bagel: " + i);
}
Assertions.assertTrue(basket.checkIfNotFull());
for (int i = 0; i < 8; i++) {
basket.add("bagel: " + i);
}
Assertions.assertFalse(basket.checkIfNotFull());
}

@Test
public void testAddBagelIfBasketIsFull(){
Basket basket = new Basket();

Assertions.assertTrue(basket.checkIfNotFull());
basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
Assertions.assertTrue(basket.checkIfNotFull());
basket.add("Blueberry");
basket.add("Strawberry");
basket.add("Plain");
Assertions.assertFalse(basket.checkIfNotFull());
}
@Test
public void testTryRemoveBagelInList(){
Basket basket = new Basket();
basket.add("Blueberry");
basket.add("Strawberry");
basket.add("Plain");
basket.add("Cookie Dough");
basket.add("Vanilla");
basket.add("Chocolate");
Assertions.assertEquals("Bagel not in list", basket.tryRemoveBagel("Redberry"));
Assertions.assertEquals("Bagel is removed from list",basket.tryRemoveBagel("Cookie Dough"));
Assertions.assertEquals("Bagel not in list", basket.tryRemoveBagel("Plain."));
Assertions.assertEquals("Bagel is removed from list", basket.tryRemoveBagel("Blueberry"));
Assertions.assertEquals("Bagel is removed from list", basket.tryRemoveBagel("Vanilla"));
}

}
63 changes: 63 additions & 0 deletions userStories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
```
1.
As a member of the public,
So I can order a bagel before work,
I'd like to add a specific type of bagel to my basket.
```

| Classes | Methods | Scenario | Output |
|---------|-------------------|---------------------------|--------------|
| Basket | add(String bagel) | User adds bagel to basket | return true |
| | | User adds empty name | return false |
| | | User adds invalid bagel | return false |


```
2.
As a member of the public,
So I can change my order,
I'd like to remove a bagel from my basket.
```
| Classes | Methods | Scenario | Output |
|---------|----------------------|----------------------|--------------|
| Basket | remove(String bagel) | if bagel in basket | return true |
| | | if bagel is null | return false |
| | | if bagel not in list | return false |


```
3.
As a member of the public,
So that I can not overfill my small bagel basket
I'd like to know when my basket is full when I try adding an item beyond my basket capacity.
```

| Classes | Methods | Scenario | Output |
|---------|------------------|----------------------|--------------|
| Basket | checkIfFull() | if list not full | return true |
| | | if list is full | return false |
| | | if bagel is null | return false |

```
4.
As a Bob's Bagels manager,
So that I can expand my business,
I’d like to change the capacity of baskets.
```

| Classes | Methods | Scenario | Output |
|---------|------------------------------|------------------|--------------|
| Basket | changeCapacity(int capacity) | if capacity > 0 | return true |
| | | if capacity < -1 | return false |

```
5.
As a member of the public
So that I can maintain my sanity
I'd like to know if I try to remove an item that doesn't exist in my basket.
```

| Classes | Methods | Scenario | Output |
|---------|------------------------------------|----------------------|-------------------------------------|
| Basket | tryRemoveBagelInList(String bagel) | if bagel not in list | return "Bagel not in list" |
| | | if bagel in list | return "Bagel is removed from list" |