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

| Classes | Variables | Methods | Scenario | Outcomes |
|----------|-----------------------------------|------------------------|-----------------------------------------|------------------------------------------|
| `Basket` | `ArrayList<String> bagels` | `order(String bagel)` | If bagels contains bagel | Print confirmation and return true |
| | `ArrayList<String> orderedBagels` | | If bagels does not contain bagel | Print error and return false |
| | `int capacity` | `remove(String bagel)` | If orderedBagels contains bagel | Print confirmation and return true |
| | | | If orderedBagels does not contain bagel | Print error and return false |
| | | `full()` | If orderedBagels is full | Print full message and return true |
| | | | If orderedBagels is not full | Return not full message and return false |
| | | `setCapacity(int i)` | | Capacity is changed |
47 changes: 47 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {

ArrayList<String> bagels = new ArrayList<String>();
ArrayList<String> orderedBagels = new ArrayList<>();
int capacity;

Basket(){
bagels.add("bagelOne");
bagels.add("bagelTwo");
bagels.add("bagelThree");
capacity = 5;
}

public boolean order(String bagel){
if(!bagels.contains(bagel)){
full();
System.out.println("Bagel not found!");
return false;
}
orderedBagels.add(bagel);
System.out.println("Bagel added.");
return true;
}

public boolean remove(String bagel){
if(orderedBagels.contains(bagel)){
orderedBagels.remove(bagel);
System.out.println("Bagel removed.");
return true;
}
System.out.println("Bagel not found!");
return false;
}

public boolean full(){
if(orderedBagels.size() >= capacity){
System.out.println("Basket is full!");
return true;
}
System.out.println("Basket is not full.");
return false;
}

public boolean setCapacity(int newCap){
capacity = newCap;
return true;
}
}
54 changes: 54 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,58 @@

class BasketTest {

Basket basket = new Basket();

@Test
public void testOrderExists(){
Assertions.assertFalse(basket.order(""));
}

@Test
public void testBagelsExist(){
Assertions.assertFalse(basket.bagels.isEmpty());
}

@Test
public void testOrderFunction(){
Assertions.assertFalse(basket.order(("bagelFour")));
}

@Test
public void testOrderedBagelsExist(){
Assertions.assertTrue(basket.orderedBagels.isEmpty());
}

@Test
public void testOrderAddsToOrderedBagels(){
basket.order("bagelOne");
Assertions.assertTrue(basket.orderedBagels.contains("bagelOne"));
}

@Test
public void testRemoveExists(){
basket.order("bagelOne");
Assertions.assertTrue(basket.remove("bagelOne"));
}

@Test
public void testRemoveFunction(){
basket.order("bagelOne");
Assertions.assertTrue(basket.orderedBagels.contains("bagelOne"));
Assertions.assertFalse(basket.remove("bagelTwo"));
Assertions.assertTrue(basket.remove("bagelOne"));
Assertions.assertFalse(basket.remove("bagelOne"));
Assertions.assertFalse(basket.orderedBagels.contains("bagelOne"));
}

@Test
public void testFullFunction(){
Assertions.assertFalse(basket.full());
}

@Test
public void testSetCapacityFunction(){
Assertions.assertTrue(basket.setCapacity(15));
Assertions.assertEquals(15, basket.capacity);
}
}