Browse Source

More tests added for items class

Lauren Green 5 years ago
parent
commit
62c8e1d13c

+ 28
- 0
src/test/java/io/zipcoder/ItemParserTest.java View File

@@ -62,4 +62,32 @@ public class ItemParserTest {
62 62
         Integer actual = itemParser.findKeyValuePairsInRawItemData(itemArray.get(0)).size();
63 63
         assertEquals(expected, actual);
64 64
     }
65
+
66
+    @Test
67
+    public void identifyNameTestCookieWithZero(){
68
+        String expected = "cookies";
69
+        String actual = itemParser.identifyName("C0oKies");
70
+        assertEquals(expected, actual);
71
+    }
72
+
73
+    @Test
74
+    public void identifyNameTestNull(){
75
+        String expected = null;
76
+        String actual = itemParser.identifyName("bob");
77
+        assertEquals(expected, actual);
78
+    }
79
+
80
+    @Test
81
+    public void identifyNameTestApples(){
82
+        String expected = "apples";
83
+        String actual = itemParser.identifyName("aPpLEs");
84
+        assertEquals(expected, actual);
85
+    }
86
+
87
+    @Test
88
+    public void identifyNameTestBread(){
89
+        String expected = "bread";
90
+        String actual = itemParser.identifyName("BReAD");
91
+        assertEquals(expected, actual);
92
+    }
65 93
 }

+ 73
- 0
src/test/java/io/zipcoder/ItemsTest.java View File

@@ -0,0 +1,73 @@
1
+package io.zipcoder;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.util.HashMap;
8
+
9
+public class ItemsTest {
10
+
11
+    Items items = new Items();
12
+
13
+    @Before
14
+    public void setUp() throws Exception {
15
+        Item item1 = new Item("Milk", 3.40, "Food", "11/12/2020");
16
+        Item item2 = new Item("Milk", 1.45, "Food", "11/12/2020");
17
+        Item item3 = new Item("Milk", 3.40, "Food", "12/5/2020");
18
+        Item item4 = new Item("Cookies", 1.75, "Food", "11/12/2020");
19
+        Item item5 = new Item("Apples", 0.75, "Food", "11/12/2020");
20
+        Item item6 = new Item("Bread", 1.00, "Food", "11/12/2020");
21
+        Item item7 = new Item("Bread", 1.40, "Food", "11/12/2020");
22
+        Item item8 = new Item("Bread", 1.00, "Food", "11/12/2020");
23
+
24
+        items.add(item1);
25
+        items.add(item2);
26
+        items.add(item3);
27
+        items.add(item4);
28
+        items.add(item5);
29
+        items.add(item6);
30
+        items.add(item7);
31
+        items.add(item8);
32
+    }
33
+
34
+    @Test
35
+    public void testGetMilk() {
36
+        Items milkItems = items.getMilks();
37
+        int expected = 3;
38
+        int actual = milkItems.size();
39
+        Assert.assertEquals(expected, actual);
40
+    }
41
+
42
+    @Test
43
+    public void testGetBread() {
44
+        Items breadItems = items.getBread();
45
+        int expected = 3;
46
+        int actual = breadItems.size();
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+
50
+    @Test
51
+    public void testGetCookies() {
52
+        Items cookieItems = items.getCookies();
53
+        int expected = 1;
54
+        int actual = cookieItems.size();
55
+        Assert.assertEquals(expected, actual);
56
+    }
57
+
58
+    @Test
59
+    public void testGetApples() {
60
+        Items appleItems = items.getApples();
61
+        int expected = 1;
62
+        int actual = appleItems.size();
63
+        Assert.assertEquals(expected, actual);
64
+    }
65
+
66
+    @Test
67
+    public void testGetMilkPrices() {
68
+        Items milkItems = items.getMilks();
69
+        HashMap<Double, Integer> milkPrices = milkItems.getPriceCount();
70
+        Assert.assertEquals(2, (int) milkPrices.get(3.40));
71
+        Assert.assertEquals(1, (int) milkPrices.get(1.45));
72
+    }
73
+}