Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5d71efb
Done with first test
sebgro98 Aug 14, 2024
d7daef2
First test is now passing
sebgro98 Aug 14, 2024
71b311f
Did second testing in which im checking if the bagel string exsists i…
sebgro98 Aug 14, 2024
a732e12
Second test is now passing
sebgro98 Aug 14, 2024
a85349e
Added the arraylist for the basked and message for user when somethin…
sebgro98 Aug 14, 2024
025ec52
Added test for removing bagel in which doesn't exist
sebgro98 Aug 14, 2024
f059ed9
Test for removing bagel passes
sebgro98 Aug 14, 2024
a2bf646
Trying again to remove bagel that doesnt exist
sebgro98 Aug 14, 2024
49218b2
Testing to see if we have reached max capacity
sebgro98 Aug 14, 2024
672c48b
We have now reached max capacity so test is working
sebgro98 Aug 14, 2024
6b970fa
added test for increment capacity by Dave test fails as he is not bob
sebgro98 Aug 14, 2024
cdecab0
Changed the function in incrementCapacity as i made a mistake with th…
sebgro98 Aug 14, 2024
8e8ad38
Now the test is passing as it was not bob how did the change
sebgro98 Aug 14, 2024
bd3c826
Added test for which it's bob trying to change the capacity
sebgro98 Aug 14, 2024
3d3da74
Fixed some mistakes in my testing hopefully it's okey
sebgro98 Aug 14, 2024
31e05d1
Cleaned up code, thinking im done?
sebgro98 Aug 14, 2024
6b68a83
Added a test in which if i send an empty string to remove i will get …
sebgro98 Aug 14, 2024
5d03b9a
Added more test cases
sebgro98 Aug 14, 2024
31700a3
added to see if you can have two of the same bagels in the basket
sebgro98 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
53 changes: 53 additions & 0 deletions DomainModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Exercise Requirements

- Use only the Basket class and BasketTest class provided. Later, you'll be building another version of this project using multiple classes together as we learn object-oriented programming.
- You **must** design a domain model before you begin building. Add your model as either a `.md` file or a screenshot
- You **must** use the Red Green Refactor approach to write your code. To demonstrate this, `git commit` after writing your test and commit again after writing the source code to pass it

## 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.
```
## Domain model Basket

| Variables | Methods | Scenario | Outputs |
|------------------------------------|------------------------------------------------------|--------------------------------|-------------------------------------------------------------|
| `ArrayList<String> bagelsInStore` | | | |
| `ArrayList<String> bagelsInBasket` | `boolean removeBagel(String bagel)` | Removing a specific bagel | Sysout bagel removed from basket or bagel doesnt exist |
| | `boolean addBagel(String bagel)` | user adds bagels to basket | Sysout if reched max capacity or if not output baggel added | //Notes Check by array length if the length becomes longer then max capacity
| `int maxCapacity` | `boolean incrementCapacity(int amount, String name)` | Bob wants to grow his capacity | return true if incremented and sysout that it got higher |


## Domain model
41 changes: 41 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
ArrayList<String> bagelsInStore = new ArrayList<>();
ArrayList<String> bagelsInBasket = new ArrayList<>();
int maxCapacity = 5;

public Basket() {
bagelsInStore.add("Cheese Bagel");
bagelsInBasket.add("Pepperoni Bagel");
bagelsInBasket.add("Cheese Bagel");
bagelsInBasket.add("bagel1");

}

public boolean addBagel(String bagel) {
if(bagel.isEmpty() || !(bagelsInStore.contains(bagel)) || maxCapacity == bagelsInBasket.size() ) {
return false;
}
bagelsInBasket.add(bagel);
System.out.println("Your: " + bagel + " Has been added to the basket");
return true;
}

public boolean removeBagel(String bagel) {
if(bagel.isEmpty() || !(bagelsInBasket.contains(bagel))) {
System.out.println("The item you're trying to remove doesn't exist.");
return false;
}
bagelsInBasket.remove(bagel);
System.out.println("The item " + bagel + " Got removed from your basket");
return true;
}

public boolean incrementCapacity(int amount, String name) {
if(!name.equalsIgnoreCase("bob")) {
return false;
}
maxCapacity = maxCapacity + amount;
System.out.println("You have now updated the capacity");
return true;
}

}
42 changes: 42 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,47 @@
import org.junit.jupiter.api.Test;

class BasketTest {
Basket basket;

BasketTest(){
basket = new Basket();
}

@Test
public void testAddBagelExists() {
Assertions.assertFalse(basket.addBagel(""));

}

@Test
public void testAddBagel() {
Assertions.assertTrue(basket.addBagel("Cheese Bagel"));
Assertions.assertTrue(basket.addBagel("Cheese Bagel"));
Assertions.assertFalse(basket.addBagel("Ham Bagel"));
Assertions.assertTrue(basket.bagelsInBasket.contains("Cheese Bagel"));
Assertions.assertFalse(basket.bagelsInBasket.contains("Ham Bagel"));


}
@Test
public void testRemoveBagel() {
Assertions.assertFalse(basket.addBagel(""));
Assertions.assertFalse(basket.removeBagel("Double Cheese Bagel")); // doesn't exist
Assertions.assertTrue(basket.removeBagel("Pepperoni Bagel"));
Assertions.assertFalse(basket.removeBagel("Pepperoni Bagel"));// exist
Assertions.assertFalse(basket.bagelsInBasket.contains("Pepperoni Bagel"));
Assertions.assertFalse(basket.bagelsInBasket.contains("Double Cheese Bagel"));
}

@Test
public void testBucketIsNotFull() {
Assertions.assertTrue(basket.addBagel("Cheese Bagel"));
}

@Test
public void testIncrementBucketCapacity() {
Assertions.assertFalse(basket.incrementCapacity(2, "Dave"));
Assertions.assertTrue(basket.incrementCapacity(2, "bob"));
}

}