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
46 changes: 46 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

## User Stories

```
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.
```

```
2.
As a member of the public,
So I can change my order,
I'd like to remove a bagel from my basket.
```

```
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.
```

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

```
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.
```

| Class | Variables | Methods | Scenario | Outcome | Notes |
|------|------------------------------------------|-------------------------------------|---------------------------------------------|------------------------------------------------------------------------------------------------------------|------------------------------------|
|`Basket` | `int basketSize` | | | | max size of new baskets |
| | `private ArrayList<String> basket `| | | | list containing the bagels added |
| | | `boolean addBagel(String type) ` | User want to add a specific bagel | If the basket has space, then add the bagel.<br/> If the basket is full, then print a message to the user. | |
| | | `boolean removeBagel(String type) ` | User removes a specific bagel | If basket is not empty, then remove the bagel.<br/> If the basket is empty, print an error message to user. | |
| | | `int getMaxSize() ` | Manager wants to know the max size of basket | int basketSize is returned. | |
| | | `void setMaxSize(int newSize)` | Manager sets the max size of basket | basketSize is changed | |
50 changes: 50 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
private int maxBasketSize = 5; // default value
private ArrayList<String> basket = new ArrayList<>();

public boolean addBagel(String type){
if (basket.size() < maxBasketSize){
basket.add(type);
return true;
}
System.out.println("Basket is full. Can't add " + type);
return false;
}

public boolean removeBagel(String type){
if(basket.contains(type)){
basket.remove(type);
return true;
}

if(basket.isEmpty()) {
System.out.println("Basket is empty.");
}
else {
System.out.println(type + " is not in basket.");
}
return false;
}

/**
* Removes the last bagel
* @return boolean
*/
public boolean removeBagel(){
if(basket.isEmpty()){
System.out.println("Basket is empty.");
return false;
}
basket.removeLast();
return true;

}

public int getMaxSize(){
return maxBasketSize;
}

public void setMaxSize(int newSize){
maxBasketSize = newSize;
}

}
58 changes: 58 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,62 @@

class BasketTest {

@Test
void testAddBagel(){
Basket basket = new Basket();

// max size = 5;
for (int i = 0; i < 5; i++)
Assertions.assertTrue(basket.addBagel("Whole wheat"));
Assertions.assertFalse(basket.addBagel("Whole wheat"));

}

@Test
void testRemoveBagel() {
Basket basket = new Basket();
basket.addBagel("Italian");
Assertions.assertTrue(basket.removeBagel("Italian"));
Assertions.assertFalse(basket.removeBagel("Whole wheat"));
Assertions.assertFalse(basket.removeBagel("Italian"));
}


@Test
void testRemoveBagelOverloaded(){
Basket basket = new Basket();
basket.addBagel("Italian");
Assertions.assertTrue(basket.removeBagel());
Assertions.assertFalse(basket.removeBagel());

basket.addBagel("a round one");
Assertions.assertTrue(basket.removeBagel());
Assertions.assertFalse(basket.removeBagel());
Assertions.assertFalse(basket.removeBagel());
}


@Test
void testGetMaxSize(){
Basket basket = new Basket();
Assertions.assertEquals(basket.getMaxSize(), 5);
}

@Test
void testSetMaxSize(){
Basket basket = new Basket();
Assertions.assertEquals(basket.getMaxSize(), 5);

basket.setMaxSize(10);
Assertions.assertEquals(basket.getMaxSize(), 10);

basket.setMaxSize(15);
Assertions.assertNotEquals(basket.getMaxSize(), 10);
Assertions.assertEquals(basket.getMaxSize(), 15);

basket.setMaxSize(3);
Assertions.assertNotEquals(basket.getMaxSize(), 10);
Assertions.assertNotEquals(basket.getMaxSize(), 15);
Assertions.assertEquals(basket.getMaxSize(), 3);
}
}