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


| Classes | Method | Member Variables | Scenario | Output |
|----------|------------------------------------------------|-----------------------|---------------------------------------------------------------------------------------------------|------------|
| `Basket` | `addBagel(String bagelType)` | `List<String> bagels` | If bagels.length; < basketLimit, add the bagel to the list. | true |
| | | `int basketLimit` | Else: let user know it is full. | false |
| | | | | |
| | `removeBagel(String bagelType)` | `int managerKey` | If bagelType in bagels, remove it from the basket and notify user with true. | true |
| | | | Else: no bagelType found in bagel, notify user with false. | false |
| | | | | |
| | `changeBasketCapacity(int newBasketCapacity)` | | If user is manager, replace the basketLimit with newBasketCapacity. Success of change equals true | true/false |





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

import java.util.ArrayList;

public class Basket {

private ArrayList<String> bagels;
private int basketLimit = 4;
private int managerKey = 9999;

public Basket() {
this.bagels = new ArrayList<>();

}

public boolean addBagel(String bagelType) {
if (bagels.size() < basketLimit) {
bagels.add(bagelType);

return true;
}


return false;
}

public boolean removeBagel(String bagelType) {
if (bagels.contains(bagelType)){
bagels.remove(bagelType);

return true;
}
return false;
}


public boolean changeBasketCapacity(int newBasketCapacity){
if(managerKey == 9999){
basketLimit = newBasketCapacity;

return true;
}
return false;
}
}
38 changes: 38 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,42 @@

class BasketTest {

@Test
public void testAddBagel() {
Basket basket = new Basket();
String bagelType = "Original";

Assertions.assertTrue(basket.addBagel(bagelType));

}

@Test
public void testRemoveBagel() {
Basket basket = new Basket();
basket.addBagel("Special");

String bagelType = "Special";

Assertions.assertTrue(basket.removeBagel(bagelType));

}

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

basket.addBagel("Onion");
basket.addBagel("Cheese");
basket.addBagel("Lettuce");

basket.addBagel("Salt");

Assertions.assertFalse(basket.addBagel("Meat"));

basket.changeBasketCapacity(10);

Assertions.assertTrue(basket.addBagel("Plain"));

}

}