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: 9 additions & 1 deletion EXERCISE1.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Here is how one might design a domain model for the above user story:
| `CohortManager` | `search(List<String> cohorts, String name)` | If name is in list | true |
| | | If name is not in list | false |

| Classes | Methods | Scenario | Outputs | |
|---------|---------|----------|---------|---|

> **Time to analyse**
>
> Evaluate the user story and the domain model above. What assumptions did the developer have to make and what would you do differently?
Expand All @@ -44,5 +47,10 @@ I'd like to see an itemised receipt that includes the name and price of the prod
I bought as well as the quantity, and a total cost of my basket.
```



- Add your domain models to this repository as a file named `domain-model`. This should either be a `.md` file like this one, or a screenshot / picture of your work.
- Your model doesn't have to look like the example provided in this file. If you feel like you need more or less columns, feel free to go with that. There is no "right way" to do this kind of thing, we're just designing a system to make our lives easier when it comes to the coding part.
- Your model doesn't have to look like the example provided in this file. If you feel like you need more or less columns, feel free to go with that. There is no "right way" to do this kind of thing, we're just designing a system to make our lives easier when it comes to the coding part.

classes methods member variables scenario outcomes

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

import java.util.HashMap;

public class Basket {

private HashMap<String, Integer> items;

public Basket(){
this.items = new HashMap<>();
}

public boolean add(String product, int price){
if(!items.containsKey(product)){
this.items.put(product, price);

return true;
}
return false;
}

public int total(){

int total = 0;
for (int i : this.items.values()){
total += i;
}
return total;
}



}
2 changes: 2 additions & 0 deletions src/main/java/com/booleanuk/core/CohortManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public class CohortManager {



}
55 changes: 55 additions & 0 deletions src/test/java/com/booleanuk/core/BasketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.booleanuk.core;

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

public class BasketTest {

@Test
public void testBasketExist() {
Basket basket = new Basket();
String product = "Cucumber";
int price = 399;

Assertions.assertTrue(basket.add(product, price));
}

@Test
public void testBasketAddItem() {
Basket basket = new Basket();
String product = "Cucumber";
int price = 399;

Assertions.assertTrue(basket.add(product, price));
Assertions.assertFalse(basket.add(product, price));
}

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

Assertions.assertEquals(0, basket.total());
}

@Test
public void testTotalValueOfBasketOneItem(){
Basket basket = new Basket();
String product = "Cucumber";
int price = 399;
basket.add(product, price);

Assertions.assertEquals(399, basket.total());
}

@Test
public void testTotalValueOfBasketManyItems(){
Basket basket = new Basket();
basket.add("Cucumber", 10);
basket.add("Tomato", 20);
basket.add("Coffee", 30);
basket.add("Red bull", 40);

Assertions.assertEquals(100, basket.total());
}

}