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
21 changes: 21 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
| Classes | Variables | Methods | Scenario | Outcomes |
|----------------|-------------------------------------|---------------------------------------|-----------------------|----------------------|
| `CashRegister` | `Map<Integer, Integer> weightItem` | `getPriceForWeightItem(int PLUCode)` | Product is in map | Add price to total |
| | `Map<barcode, Integer> barcodeItem` | `getPriceForBarcodeItem(int barcode)` | Product is not in map | Return error message |
| | | | | |
| | `ìnt totalCost` | `getTotalCost()` | Total cost is > 0 | Return total cost |
| | | | Total cost is < 0 | Return error message |
| | | | | |
| | | `addToTotalCost(int price)` | Price is > 0 | Add to totalCost |
| | | | Price is < 0 | Return |

| Classes | Variables | Methods | Scenario | Outcomes |
|---------------|-------------------------------------------------------------|-----------------------------------------|--------------------------|--------------------------|
| `MembersDesk` | `Map<Integer, Map<Integer, List<Receipt>>> shoppingHistory` | `getShoppingHistory(int membersNumber)` | Customer is a member | Return list of purchases |
| | | | Customer is not a member | Return error message |
| | | | | |
| | | `getItemisedReceipt(int receiptNumber)` | Valid receipt number | Return receipt |
| | | | In valid receipt number | Return error message |
| | | | | |


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

import java.util.HashMap;

public class Basket {
private final HashMap<String, Integer> items = new HashMap<>();

public boolean add(String product, int price) {
if (product.isEmpty() || items.containsKey(product)) {
return false;
}
items.put(product, price);
return true;
}

public int total() {
int total = 0;

for (int price : items.values()) {
total += price;
}
return total;
}
}
38 changes: 38 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.booleanuk.core;

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

public class BasketTest {

Basket basket = new Basket();

@Test
public void addMethodExistTest() {
Assertions.assertFalse(basket.add("", 0));
}

@Test
public void addItemTest() {
Assertions.assertFalse(basket.add("", 0));
Assertions.assertTrue(basket.add("Milk", 5));
Assertions.assertFalse(basket.add("Milk", 5));
Assertions.assertTrue(basket.add("Bread", 2));
Assertions.assertTrue(basket.add("Eggs", 3));
}

@Test
public void totalTest() {
Assertions.assertTrue(basket.add("Milk", 5));
Assertions.assertTrue(basket.add("Bread", 2));
Assertions.assertTrue(basket.add("Eggs", 3));
Assertions.assertNotEquals(0, basket.total());
Assertions.assertEquals(10, basket.total());

Assertions.assertTrue(basket.add("Apple", 5));
Assertions.assertEquals(15, basket.total());

}


}