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


| Methods | Member variables | Scenario | Outputs/Results/Return values |
|-----------------|------------------|--------------------|-------------------------------|
| addBagel(bagel) | String[] bagels | if bagel add | True |
| | | if bagel add exist | False |
| | | | |
| | | |

# 2. Member class

| Methods | Member variables | Scenario | Outputs/Results/Return values |
|------------------------------------|----------------------|------------------------|-------------------------------|
| removeBagel(bagels ,bagelBasket[]) | String[] bagelBasket | if bagel exists | True |
| | | if bagel doesn't exist | False |
| | | | |
| | | |

# 3. Member class

| Methods | Member variables | Scenario | Outputs/Results/Return values |
|---------------------------------------|-----------------------|-------------------|-------------------------------|
| basketCapacity(bagels ,bagelBasket[]) | String[] bagelsBasket | if basket full | True |
| | | if bagel not full | False |
| | | | |
| | | |

# 4. Member class

| Methods | Member variables | Scenario | Outputs/Results/Return values |
|---------------------------------------|-----------------------|-------------------|-------------------------------|
| basketCapacity(bagels ,bagelBasket[]) | String[] bagelsBasket | if basket full | increaseCapacity(); |
| increaseCapacity() | int capacity = 0; | if bagel not full | False |
| | | | |
| | | |

# 5. Member class

| Methods | Member variables | Scenario | Outputs/Results/Return values |
|------------------------------------|-----------------------|-------------------------|-------------------------------|
| removeBagel(bagels ,bagelBasket[]) | String[] bagelsBasket | if bagels exist | true |
| message() | | if bagel does not exist | False |
| | | | |
| | | |
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.util.ArrayList;

public class Basket {
ArrayList<String> bagels;
int capacity = 2;
public Basket(){
this.bagels = new ArrayList<>(capacity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in this morning's session it's best not to hard code example data into your code, do it in the tests instead.

bagels.add("bagel2");
}

public boolean addBagel(String bagel){

if (bagels.contains(bagel)){
return false;
}
bagels.add(bagel);
return true;
}
public boolean removeBagel(String bagel){
if (bagels.contains(bagel)){
bagels.remove(bagel);
return true;
}
return false;
}
public boolean checkCapacity(){
if (bagels.size() >capacity ){
return true;
}
return false;
}

public int updateCapacity(int newCap){
this.capacity = newCap;
return this.capacity;
}
public String removeBagelString(String bagel){
String ut="The bagel " + bagel + " doesn't exist";
if (bagels.contains(bagel)){
bagels.remove(bagel);
ut= "The bagel " + bagel + " is removed";
}
return ut;
}

}
48 changes: 47 additions & 1 deletion src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,52 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class BasketTest {

public class BasketTest {

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

boolean result = basket.addBagel("bagel1");
Assertions.assertTrue(result);
}

@Test
public void addSpecificBagelReturnFalse(){
Basket basket = new Basket();
boolean result = basket.addBagel("bagel2");
Assertions.assertFalse(result);
}

@Test
public void removeSpecificBagelReturnTrue(){
Basket basket = new Basket();
boolean result = basket.removeBagel("bagel2");
Assertions.assertTrue(result);
}

@Test
public void checkCapacityListReturnTrue(){
Basket basket = new Basket();
basket.addBagel("bagel3");
basket.addBagel("bagel4");
basket.addBagel("bagel5");
basket.addBagel("bagel6");
boolean result = basket.checkCapacity();
Assertions.assertTrue(result);
}
@Test
public void updateCapacityReturnString(){
Basket basket = new Basket();
int updateCap=10;
String returnV = basket.removeBagelString("bagel10");
Assertions.assertEquals("The bagel " + "bagel10" + " doesn't exist",returnV);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test appears to start off with the intention of updating the capacity but then ends up with code that tries to remove an non-existent bagel from the basket.







}