Skip to content

Jonas Finborud Nyman #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
35 changes: 35 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Domain Model

## CohortManager Class

| Method | Member Variables | Scenario | Result |
|------------------------------|------------------------------|---------------------------|--------------|
| | ArrayList<String> cohortList | | |
| searchForCohort(String name) | | Name is in cohortList | Return true |
| | | Name is not in cohortList | Return false |


1.

## SupermarketCashier Class

| Method | Member Variables | Scenario | Result |
|------------------------------------------|------------------|---------------------------------------------------|------------------|
| | int totalCost | | |
| calculateCost(ArrayList<Item> groceries) | | Calculates the accumulated value of the groceries | Return totalCost |
| | | List is null | Return -1 |


2.
| Method | Member Variables | Scenario | Result |
|-----------------------------------------|--------------------|--------------------------------------------------------------------------|--------|
| | Receipt newReceipt | | |
| printReceipt(ArrayList<Item> groceries) | | Creates a receipt with createReceipt and prints the data to the terminal | |
| | | Is unable to create a receipt. Prints error-message to the terminal | |

| Method | Member Variables | Scenario | Result |
|------------------------------------------|--------------------|---------------------------------------------------------------------|-------------------|
| | Receipt newReceipt | | |
| createReceipt(ArrayList<Item> groceries) | | Creates a new receipt with the requested information and returns it | Return newReceipt |
| | | List is null | Return null |

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

import java.util.HashMap;

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

public boolean add(String product, int price) {
return items.put(product, price) == null;
}

public int total() {
int totalCost = 0;
for(String key : items.keySet()) {
totalCost += items.get(key);
}
return totalCost;
}
}
6 changes: 5 additions & 1 deletion src/main/java/com/booleanuk/core/CohortManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.booleanuk.core;

public class CohortManager {
import java.util.ArrayList;

public class CohortManager {
public boolean search(ArrayList<String> cohorts, String name) {
return cohorts.contains(name);
}
}
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 {

@Test
public void addItemThatDoesNotExist() {
Basket basket = new Basket();
Assertions.assertTrue(basket.add("milk", 2));
}

@Test
public void addItemThatAlreadyExists() {
Basket basket = new Basket();
basket.items.put("butter", 4);
Assertions.assertFalse(basket.add("butter", 4));
}

@Test
public void getCorrectTotalCost() {
Basket basket = new Basket();
basket.items.put("butter", 4);
basket.items.put("milk", 2);
basket.items.put("coffee", 7);
Assertions.assertEquals(13, basket.total());
}

@Test
public void getWrongTotalCost() {
Basket basket = new Basket();
basket.items.put("butter", 4);
basket.items.put("milk", 2);
basket.items.put("coffee", 7);
Assertions.assertNotEquals(10, basket.total());
}
}
35 changes: 35 additions & 0 deletions src/test/java/com/booleanuk/core/CohortManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;

class CohortManagerTest {

@Test
public void searchForCohortThatExists() {
// 1. Setup
CohortManager cohortManager = new CohortManager();
ArrayList<String> cohorts = new ArrayList<>() {{
add("JAEX1");
add("JAEX2");
add("JAEX3");
add("JAEX4");
add("JAEX5");
}};
String name = "JAEX5";

// 2. Execute / 3. Verify
Assertions.assertTrue(cohortManager.search(cohorts, name));
}

@Test
public void searchForCohortThatDoesNotExist() {
// 1. Setup
CohortManager cohortManager = new CohortManager();
ArrayList<String> cohorts = new ArrayList<>() {{
add("JAEX1");
add("JAEX2");
add("JAEX3");
add("JAEX4");
add("JAEX5");
}};
String name = "JAEX6";

// 2. Execute / 3. Verify
Assertions.assertFalse(cohortManager.search(cohorts, name));
}
}
Loading