|
@@ -3,7 +3,7 @@ package io.zipcoder;
|
3
|
3
|
import org.junit.Assert;
|
4
|
4
|
import org.junit.Test;
|
5
|
5
|
|
6
|
|
-import java.util.ArrayList;
|
|
6
|
+import java.util.*;
|
7
|
7
|
|
8
|
8
|
public class ListCreationTest {
|
9
|
9
|
|
|
@@ -20,44 +20,61 @@ public class ListCreationTest {
|
20
|
20
|
}
|
21
|
21
|
|
22
|
22
|
@Test
|
23
|
|
- public void testCreateGroceryList1() {
|
|
23
|
+ public void testFormattedGroceryListString(){
|
24
|
24
|
//Given
|
25
|
25
|
ListCreation list = new ListCreation();
|
26
|
|
- ListEntryPair entry = new ListEntryPair("", 0.00);
|
27
|
26
|
Item item1 = new Item("milk", 3.23, "food", "1/25/2016");
|
28
|
27
|
Item item2 = new Item("cookies", 2.50, "food", "12/03/2018");
|
|
28
|
+ Item item3 = new Item("apples", 0.35, "food","04/23/2018");
|
|
29
|
+ Item item4 = new Item("milk", 3.23, "food", "1/25/2016");
|
|
30
|
+ Item item5 = new Item("milk", 2.00, "food", "1/25/2016");
|
29
|
31
|
//When
|
30
|
|
- ArrayList<Item> itemObjects = new ArrayList<>();
|
31
|
|
- itemObjects.add(item1);
|
32
|
|
- itemObjects.add(item2);
|
33
|
|
- String expectedName = "milk";
|
|
32
|
+ ArrayList<Item> itemObjects = new ArrayList<>(Arrays.asList(item1,item2,item3,item4,item5));
|
34
|
33
|
//Then
|
35
|
|
- ArrayList<ListEntryPair> groceries = list.createNameAndPriceList(itemObjects);
|
36
|
|
- entry = groceries.get(0);
|
37
|
|
- String actualName = entry.getName();
|
38
|
|
- Assert.assertEquals(expectedName, actualName);
|
|
34
|
+ String groceryList = list.formattedGroceryListString(itemObjects);
|
|
35
|
+ boolean expected = true;
|
|
36
|
+ boolean actual = groceryList.contains("Milk");
|
|
37
|
+ Assert.assertEquals(expected, actual);
|
39
|
38
|
}
|
40
|
39
|
|
41
|
40
|
@Test
|
42
|
|
- public void testFormattedGroceryListString(){
|
43
|
|
- //Given
|
|
41
|
+ public void testKeySet(){
|
|
42
|
+ ListCreation list = new ListCreation();
|
|
43
|
+ Item item1 = new Item("apples", 0.35, "food","04/23/2018");
|
|
44
|
+ Item item2 = new Item("milk", 3.23, "food", "1/25/2016");
|
|
45
|
+ Item item3 = new Item("milk", 2.00, "food", "1/25/2016");
|
|
46
|
+ ArrayList<Item> itemObjects = new ArrayList<>(Arrays.asList(item1,item2,item3));
|
|
47
|
+ LinkedHashSet<String> actual = list.keySet(itemObjects);
|
|
48
|
+ LinkedHashSet<String> expected = new LinkedHashSet<>(Arrays.asList("apples","milk"));
|
|
49
|
+ Assert.assertEquals(expected,actual);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ @Test
|
|
53
|
+ public void testKeyString(){
|
|
54
|
+ ListCreation list = new ListCreation();
|
|
55
|
+ Item item1 = new Item("apples", 0.35, "food","04/23/2018");
|
|
56
|
+ Item item2 = new Item("milk", 3.23, "food", "1/25/2016");
|
|
57
|
+ Item item3 = new Item("milk", 2.00, "food", "1/25/2016");
|
|
58
|
+ ArrayList<Item> itemObjects = new ArrayList<>(Arrays.asList(item1, item2,item3));
|
|
59
|
+ String expected = "applesmilkmilk";
|
|
60
|
+ String actual = list.keyString(itemObjects);
|
|
61
|
+ Assert.assertEquals(expected, actual);
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void testValueCount(){
|
44
|
66
|
ListCreation list = new ListCreation();
|
45
|
|
- ArrayList<Item> itemObjects = new ArrayList<>();
|
46
|
67
|
Item item1 = new Item("milk", 3.23, "food", "1/25/2016");
|
47
|
68
|
Item item2 = new Item("cookies", 2.50, "food", "12/03/2018");
|
48
|
69
|
Item item3 = new Item("apples", 0.35, "food","04/23/2018");
|
49
|
70
|
Item item4 = new Item("milk", 3.23, "food", "1/25/2016");
|
50
|
71
|
Item item5 = new Item("milk", 2.00, "food", "1/25/2016");
|
51
|
|
- //When
|
52
|
|
- itemObjects.add(item1);
|
53
|
|
- itemObjects.add(item2);
|
54
|
|
- itemObjects.add(item3);
|
55
|
|
- itemObjects.add(item4);
|
56
|
|
- itemObjects.add(item5);
|
57
|
|
- //Then
|
58
|
|
- ArrayList<ListEntryPair> groceries = list.createNameAndPriceList(itemObjects);
|
59
|
|
- String actual = list.formattedGroceryListString(groceries);
|
60
|
|
- System.out.println(actual);
|
|
72
|
+ ArrayList<Item> itemObjects = new ArrayList<>(Arrays.asList(item1, item2, item3, item4, item5));
|
|
73
|
+ LinkedHashMap<Double,Integer> expected = new LinkedHashMap<>();
|
|
74
|
+ expected.put(3.23,2);
|
|
75
|
+ expected.put(2.00,1);
|
|
76
|
+ LinkedHashMap<Double,Integer> actual = list.valueCount(itemObjects, "milk");
|
|
77
|
+ Assert.assertEquals(expected, actual);
|
61
|
78
|
}
|
62
|
79
|
|
63
|
80
|
@Test
|