Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e9f70ce
First test failed
Valen98 Aug 14, 2024
c12cfd7
First test failed
Valen98 Aug 14, 2024
fdccd6f
Fixed my Domain model, fixed add bagel, and fixed remove bagel red test
Valen98 Aug 14, 2024
93d5de9
Red test to remove a non existing bagel
Valen98 Aug 14, 2024
3da4eb4
Red test of checkBasketSize
Valen98 Aug 14, 2024
cf06313
CheckBasketSize failed when expected true
Valen98 Aug 14, 2024
f51ec9f
CheckBasketSize failed when expected true
Valen98 Aug 14, 2024
ed3d6af
CheckBasketSize succeeded
Valen98 Aug 14, 2024
1b6f379
Tried to overfill basket, it returned false
Valen98 Aug 14, 2024
de2e779
Check if overfilling basket is possible, it is not
Valen98 Aug 14, 2024
e1298aa
Test of overfill basket is now working properly
Valen98 Aug 14, 2024
63f515b
Added a faulty test of changeBasketSizeTest
Valen98 Aug 14, 2024
332e889
Someone else tries to change size of basket
Valen98 Aug 14, 2024
2a1b777
Owner tries to change size but the test is red
Valen98 Aug 14, 2024
2ce95bc
Owner can now change the size of the basket
Valen98 Aug 14, 2024
4e31a19
Tries to add a 5th bagel when its full
Valen98 Aug 14, 2024
bd143a7
Tries to add a 5th bagel when its full but now green
Valen98 Aug 14, 2024
236a39a
Tries to change the size of basket but its red test
Valen98 Aug 14, 2024
1291e89
Tries to add two more bagels after size of basket increased by 2. red…
Valen98 Aug 14, 2024
f5e4bb1
Tries to change the size of basket but its green test
Valen98 Aug 14, 2024
266fe3f
Tries to add another bagel but the basket is full. Red test
Valen98 Aug 14, 2024
77b18c2
Tries to add another bagel but the basket is full. Green test
Valen98 Aug 14, 2024
53adea0
Tries to remove a bagel that does not exist, red test
Valen98 Aug 14, 2024
f2d96b6
User tries to remove a non-existing bagel test
Valen98 Aug 14, 2024
88d9cc4
Added clarification of what role number manager has in my domain model
Valen98 Aug 14, 2024
6cd47cb
Checked so normal user cannot change basket size
Valen98 Aug 14, 2024
6f5c203
A normal user cannot change basket size, green test
Valen98 Aug 14, 2024
e9b5420
Fixed domainModel
Valen98 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
72 changes: 72 additions & 0 deletions domainModel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
### Leo Wahlandt Domain Model


```
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 | Member Variable | Method | Scenario | Outcome |
|---------|--------------------------|------------------------------------|-----------------------------------------|---------|
| Basket | ArrayList<String> basket | add(String bagelType) | Add existing bagel into basket | true |
| | | | Try to add non-existing bagel to basket | 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 | Member Variable | Method | Scenario | Outcome |
|---------|--------------------------|-----------------------------------|--------------------------------------------|---------|
| Basket | ArrayList<String> basket | remove(String bagel) | Remove existing bagel from basket | true |
| | | | Try to remove non-existing bagel to basket | 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 | Member Variable | Method | Scenario | Outcome |
|---------|----------------------------|-------------------------|-------------------------------|---------|
| Basket | ArrayList<String> basket | checkBasketSize() | if basket size is not reached | True |
| | | | If basket size is reached | false |
| | | | | |



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

Manager has role number 0 for Admin
```
| Classes | Member Variable | Method | Scenario | Outcome |
|---------|----------------------------|---------------------------------------------|--------------------------------------|---------|
| Basket | ArrayList<String> basket | changeBasketSize(int memberId, int newSize) | Owner change basket size | true |
| | | | If someone else tries to change size | 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 | Member Variable | Method | Scenario | Outcome |
|---------|---------------------------|-----------------------|---------------------------------------------|------------------------------------|
| Basket | ArrayList<String> basket | remove(String bagel) | Try to remove non-existing bagel to basket | "Cannot remove non-existing bagel" |
| | | | | |
| | | | | |
43 changes: 43 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
package com.booleanuk.core;

import java.sql.Array;
import java.util.ArrayList;
import java.util.HashMap;

public class Basket {
ArrayList<String> basket;
int basketSize;

public Basket() {
this.basket = new ArrayList<>();
this.basketSize = 4;
}

public boolean add(String bagel) {
if(this.basket.size() < this.basketSize) {
basket.add(bagel);
return basket.contains(bagel);
}
else {
return false;
}

}

public boolean remove(String bagel) {
if(basket.contains(bagel)) {
basket.remove(bagel);
return true;
}
return false;
}

public boolean checkBasketSize() {
return basket.size() <= basketSize;
}

public boolean changeBasketSize(int memberId, int newSize) {
if(memberId == 0) {
this.basketSize = newSize;
return true;
}
else {
return false;
}
}
}
69 changes: 69 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,73 @@

class BasketTest {

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

Assertions.assertTrue(basket.add("Sesame"));
}

@Test
public void removeBagelTest() {
Basket basket = new Basket();
basket.add("Plain");
Assertions.assertTrue(basket.remove("Plain"));

}

@Test
public void checkBasketSize() {
Basket basket = new Basket();
Assertions.assertTrue(basket.checkBasketSize());
}

@Test
public void addBagelToFullBasket() {
Basket basket = new Basket();
basket.add("Plain");
basket.add("Sesame");
basket.add("Mixed");
basket.add("Everything bagel");
Assertions.assertTrue(basket.checkBasketSize());

// Try to add basket when full
Assertions.assertFalse(basket.add("Plain"));
}

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

Assertions.assertFalse(basket.changeBasketSize(1, 1));
Assertions.assertTrue(basket.changeBasketSize(0, 6));
}

@Test
public void changeBasketSizeWhenFullTest() {
Basket basket = new Basket();
basket.add("Sesame");
basket.add("Sesame");
basket.add("Sesame");
basket.add("Sesame");
Assertions.assertFalse(basket.add("Sesame"));


Assertions.assertTrue(basket.changeBasketSize(0, 6));
Assertions.assertTrue(basket.add("Plain"));
Assertions.assertTrue(basket.add("Plain"));
//Basket full
Assertions.assertFalse(basket.add("Plain"));
Assertions.assertFalse(basket.changeBasketSize(1, 7));
Assertions.assertFalse(basket.add("Plain"));
}
//$ git commit -m "Checked so normal user cannot change basket size"
@Test
public void removeNonExistingBagelTest(){
Basket basket = new Basket();
basket.add("Sesame");
basket.add("Sesame");
Assertions.assertFalse(basket.remove("Plain"));
}

}