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

| Classes | Methods | Scenario | Outputs |
|----------|-----------------------------|--------------------------------|---------|
| `Basket` | `AddBagel(String bagel)` | Add bagel | bool |
| | `RemoveBagel(String bagel)` | Remove bagel | bool |
| | `IsFull()` | Check capacity | bool |
| | `SetCapacity(int capacity)` | Change capacity | |
| | `RemoveBagel()` | Remove a bagel that dont exist | int |
58 changes: 58 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
//Basket.java
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {
public ArrayList<String> baskets;
private int capacity;

public Basket() {

this.baskets = new ArrayList<>();
this.capacity = 2;

}

public boolean add(String bagel) {

if (this.baskets.size() < this.capacity) {

return this.baskets.add(bagel);

}

return false;
}

public boolean remove(String bagel) {

return this.baskets.remove(bagel);

}

public boolean IsFull() {

return this.baskets.size() >= this.capacity;

}

public void setCapacity(int capacity) {

if (capacity > 0) {

this.capacity = capacity;

}
}

public int removeBagel(String bagel) {

if (this.baskets.contains(bagel)) {

this.baskets.remove(bagel);
return 1;

} else {

return -1;

}
}

}
60 changes: 59 additions & 1 deletion src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
// BasketTest.java
package com.booleanuk.core;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

class BasketTest {

}
ArrayList<String> baskets;

@Test
public void testAddBagel() {

Basket basket = new Basket();
Assertions.assertTrue(basket.add("bagel1"));

}

@Test
public void testRemoveBagel() {

Basket basket = new Basket();
basket.add("bagel1");

Assertions.assertTrue(basket.remove("bagel1"));

}

@Test
public void testIsFull() {

Basket basket = new Basket();

Assertions.assertTrue(basket.add("bagel1"));
Assertions.assertTrue(basket.add("bagel2"));

Assertions.assertTrue(basket.IsFull());

}

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

Assertions.assertTrue(basket.add("bagel1"));
Assertions.assertTrue(basket.add("bagel2"));
Assertions.assertFalse(basket.add("bagel3"));

basket.setCapacity(3);

Assertions.assertTrue(basket.add("bagel3"));

}

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

basket.add("bagel1");

Assertions.assertEquals(1, basket.removeBagel("bagel1"));
Assertions.assertEquals(-1, basket.removeBagel("bagel2"));
}
}