Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3deae8a
Domain model created with the user stories
Aug 14, 2024
46c0303
Changed domain model slightly
Aug 14, 2024
1058311
Added test for adding a bagel to basket
Aug 14, 2024
8092e4f
Added an assumption to domain model
Aug 14, 2024
9813c3b
Implemented constructor in Basket. Implemented add-method in Basket.
Aug 14, 2024
285c16c
Updated domain model assumption
Aug 14, 2024
c01b6f5
Added test for removing a bagel from Basket
Aug 14, 2024
3175d3c
Added test for isFull method
Aug 14, 2024
dca6e21
Added code for removing a bagel
Aug 14, 2024
d0bfb6f
Implemented isFull method in Basket
Aug 14, 2024
ca2203f
Changed domain model
Aug 14, 2024
4426a69
Added test for changing the capacity of a Basket
Aug 14, 2024
cd53f9f
Implemented functionality to change a Basket's capacity
Aug 14, 2024
14d1347
Revert domain model to previous
Aug 14, 2024
551be9f
Added test for checking negative capacity input
Aug 14, 2024
fdcc207
Checking for negativ value input in changeCapacity method in Basket
Aug 14, 2024
e151310
Added test to check if given new capacity is less than the number of …
Aug 14, 2024
ad4755f
Implemented check for if given new capacity is less than the number o…
Aug 14, 2024
0dd1e94
Added test to check so that the public cannot change the Basket capac…
Aug 14, 2024
8b4154d
Added code to check so that only Bob Bagel's managers can change the …
Aug 14, 2024
b8429cc
Added test for checking if removing a non-existant bagel is not possi…
Aug 14, 2024
64fb422
One test failed, fixed itt
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
18 changes: 18 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Domain model

Assuming that:

- A userType of 0 is a Bob Bagel's manager
- A userType of 1 is the public
- Bagels are unique; there cannot be two or more of the same bagels in the same basket

| Classes | Methods | Scenario | Outputs |
|----------|-------------------------------------------------|------------------------------------------------|---------|
| `Basket` | `add(String bagel)` | Successfully added to basket | true |
| | | Failed to add to basket (e.g., already exists) | false |
| | `remove(String bagel)` | Successfully removed from basket | true |
| | | Failed to remove from basket | false |
| | `isFull()` | Basket is full | true |
| | | Basket is not full | false |
| | `changeCapacity(int newCapacity, int userType)` | Successfully changed capacity of baskets | true |
| | | Failed to change capacity of baskets | false |
35 changes: 35 additions & 0 deletions src/main/java/com/booleanuk/core/Basket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
package com.booleanuk.core;

import java.util.ArrayList;

public class Basket {

private final int DEFAULT_CAPACITY = 10; // Assuming basket has capacity of 10 from beginning

ArrayList<String> bagels;
private int capacity;

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

public boolean add(String bagel) {
if (this.bagels.contains(bagel) || this.bagels.size() == this.capacity) {
return false;
}
this.bagels.add(bagel);
return true;
}

public boolean remove(String bagel) {
return this.bagels.remove(bagel);
}

public boolean isFull() {
return this.bagels.size() == this.capacity;
}

public boolean changeCapacity(int newCapcity, int userType) {
if (newCapcity < 0 || newCapcity < this.bagels.size() || userType != 0) return false;

this.capacity = newCapcity;
return true;
}

}
85 changes: 85 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,89 @@

class BasketTest {

public BasketTest() {

}

@Test
public void testAddBagel() {
Basket b = new Basket();
Assertions.assertTrue(b.add("testBagel"));
}

@Test
public void testRemoveBagel() {
Basket b = new Basket();
b.add("test");
Assertions.assertTrue(b.remove("test"));
}

@Test
public void testRemoveBagelNotExisting() {
Basket b = new Basket();

Assertions.assertFalse(b.remove("test"));
}

@Test
public void testIsBasketFull() {
Basket b = new Basket();
b.add("test");
b.add("test2");
b.add("test3");
b.add("test4");
b.add("test5");
b.add("test6");
b.add("test7");
b.add("test8");
b.add("test9");
b.add("test10");
Assertions.assertTrue(b.isFull());
}

@Test
public void testChangeCapacity() {
Basket b = new Basket();
b.add("test");
b.add("test2");
b.add("test3");
b.add("test4");
b.add("test5");
b.add("test6");
b.add("test7");
b.add("test8");
b.add("test9");
b.add("test10");

Assertions.assertTrue(b.isFull());

b.changeCapacity(11, 0);

Assertions.assertFalse(b.isFull());
}

@Test
public void testChangeCapacityInputNotNegative() {
Basket b = new Basket();

Assertions.assertFalse(b.changeCapacity(-1, 0));
}

@Test
public void testChangeCapacityNotLessThanBagelsInBasket() {
Basket b = new Basket();

b.add("test");
b.add("test2");

Assertions.assertFalse(b.changeCapacity(1, 1));
}

@Test
public void testPublicCannotChangeBasketCapacity() {
Basket b = new Basket();

Assertions.assertFalse(b.changeCapacity(20, 1));
}

}