Browse Source

tests written, passing 100%

jacob andersen 6 years ago
parent
commit
cfc3e15e2e

+ 6
- 6
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java View File

@@ -18,16 +18,16 @@ public class Inventory {
18 18
                 {
19 19
                     if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros"))
20 20
                     {
21
-                        items[i].setQuality(items[i].getQuality() - 1);
21
+                        items[i].setQuality(items[i].getQuality() - 1); //sulfuras never decrease in quality
22 22
                     }
23 23
                 }
24 24
             } else
25 25
                 {
26
-                if (items[i].getQuality() < 50)
26
+                if (items[i].getQuality() < 50) // quality of item never less than 50
27 27
                 {
28 28
                     items[i].setQuality(items[i].getQuality() + 1);
29 29
 
30
-                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert")
30
+                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") // start of backstage pass details
31 31
                     {
32 32
                         if (items[i].getSellIn() < 11)
33 33
                         {
@@ -48,7 +48,7 @@ public class Inventory {
48 48
                 }
49 49
             }
50 50
 
51
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros"))
51
+            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) // sulfuras never loses value
52 52
             {
53 53
                 items[i].setSellIn(items[i].getSellIn() - 1);
54 54
             }
@@ -61,9 +61,9 @@ public class Inventory {
61 61
                     {
62 62
                         if (items[i].getQuality() > 0)
63 63
                         {
64
-                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros"))
64
+                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) //sulfuras never loses value
65 65
                             {
66
-                                items[i].setQuality(items[i].getQuality() - 1);
66
+                                items[i].setQuality(items[i].getQuality() - 1); // other depreciate
67 67
                             }
68 68
                         }
69 69
                     } else

+ 182
- 40
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

@@ -6,106 +6,248 @@ import org.junit.Test;
6 6
 
7 7
 public class InventoryTest {
8 8
 
9
+    Item genericItem = new Item("Generic Item", 7, 25);
9 10
     Item agedbrietest = new Item("Aged Brie", 7, 4);
10
-    Item backstagepasstest = new Item("Backstage passes to a TAFKAL80ETC concert", 13, 4);
11
-    Item sulfurastest = new Item("Sulfuras, Hand of Ragnaros", 7, 4);
11
+    Item backstagepasstest = new Item("Backstage passes to a TAFKAL80ETC concert", 13, 45);
12
+    Item sulfurastest = new Item("Sulfuras, Hand of Ragnaros", 7, 20);
12 13
 
13
-    Item[] inventoryList =  {agedbrietest,backstagepasstest,sulfurastest};
14
+    Item[] inventoryList = {genericItem, agedbrietest, backstagepasstest, sulfurastest};
14 15
 
15 16
     @Test
16 17
     public void updateQualityTest() {
17 18
         Inventory test = new Inventory(inventoryList);
19
+        int before = inventoryList[0].getQuality();
18 20
         test.updateQuality();
19
-
20
-        int expected = agedbrietest.getQuality();
21
-        int actual = 5;
22
-        Assert.assertEquals(expected, actual);
21
+        int after = inventoryList[0].getQuality();
22
+        //int expected = 5;
23
+        //int actual = agedbrietest.getQuality();
24
+        Assert.assertTrue(before > after);
23 25
     }
24
-@Test
25
-        public void aged_sellInTest(){
26
+
27
+    @Test
28
+    public void aged_sellInTest() {
26 29
         Inventory test = new Inventory(inventoryList);
27 30
 
28 31
         test.updateQuality();
29 32
 
30
-        int expected=agedbrietest.getSellIn();
31
-        int actual=6;
32
-        Assert.assertEquals(expected,actual);
33
+        int expected = 6;
34
+        int actual = agedbrietest.getSellIn();
35
+        Assert.assertEquals(expected, actual);
33 36
     }
37
+
34 38
     @Test
35 39
     public void sulfur_sellInTest() {
36 40
         Inventory test = new Inventory(inventoryList);
37 41
 
38 42
         test.updateQuality();
39 43
 
40
-        int expected = sulfurastest.getSellIn();
41
-        int actual = 7;
44
+        int expected = 7;
45
+        int actual = sulfurastest.getSellIn();
42 46
         Assert.assertEquals(expected, actual);
43 47
     }
44 48
 
45 49
     @Test
46
-    public void backstage_sellInTest(){
50
+    public void backstage_sellInTest() {
47 51
         Inventory test = new Inventory(inventoryList);
48 52
 
49 53
         test.updateQuality();
50 54
 
51
-        int expected=backstagepasstest.getSellIn();
52
-        int actual=12;
53
-        Assert.assertEquals(expected,actual);
55
+        int expected = 12;
56
+        int actual = backstagepasstest.getSellIn();
57
+        Assert.assertEquals(expected, actual);
54 58
     }
59
+
55 60
     public void setNameTest() {
56
-        sulfurastest.setName("sulphura");
57
-        sulfurastest.getName();
58 61
 
62
+
63
+        sulfurastest.setName("sulphura");
59 64
         String expected = "sulphura";
60
-        String actual = "sulphura";
61
-        Assert.assertEquals(1, 1);
65
+        String actual = sulfurastest.getName();
66
+        Assert.assertEquals(expected,actual);
62 67
     }
68
+
63 69
     @Test
64 70
     public void getNameTest() {
65
-        agedbrietest.getName();
71
+
66 72
 
67 73
         String expected = "Aged Brie";
68
-        String actual = "Aged Brie";
69
-        Assert.assertEquals(1, 1);
74
+        String actual = agedbrietest.getName();
75
+        Assert.assertEquals(expected, actual);
70 76
     }
71 77
 
72 78
     @Test
73 79
     public void getQualityTest() {
74 80
 
75 81
 
76
-        agedbrietest.getQuality();
77
-
78 82
         int expected = 4;
79
-        int actual = 4;
80
-        Assert.assertEquals(1, 1);
83
+
84
+        int actual = agedbrietest.getQuality();
85
+        Assert.assertEquals(expected, actual);
81 86
     }
82 87
 
83 88
     @Test
84 89
     public void setQualityTest() {
85 90
         agedbrietest.setQuality(8);
86
-        agedbrietest.getQuality();
91
+
87 92
 
88 93
         int expected = 8;
89
-        int actual = 8;
90
-        Assert.assertEquals(1, 1);
94
+        int actual = agedbrietest.getQuality();
95
+        Assert.assertEquals(expected, actual);
91 96
     }
92 97
 
93 98
     @Test
94 99
     public void getSellinTest() {
95
-        backstagepasstest.getSellIn();
100
+
96 101
 
97 102
         int expected = 13;
98
-        int actual = 13;
99
-        Assert.assertEquals(1, 1);
103
+        int actual = backstagepasstest.getSellIn();
104
+        Assert.assertEquals(expected, actual);
100 105
     }
106
+
101 107
     @Test
102
-    public void setSellInTest(){
108
+    public void setSellInTest() {
103 109
         sulfurastest.setSellIn(4);
104
-        sulfurastest.getSellIn();
110
+
105 111
 
106 112
         int expected = 4;
107
-        int actual = 4;
108
-        Assert.assertEquals(1, 1);
109
-}
113
+        int actual = sulfurastest.getSellIn();
114
+        Assert.assertEquals(expected, actual);
115
+    }
116
+
117
+    @Test
118
+    public void sellByDatePassedTest() {
119
+        Inventory test = new Inventory(inventoryList);
120
+        genericItem.setSellIn(1);
121
+        test.updateQuality();
122
+        int before = genericItem.getQuality();
123
+        test.updateQuality();
124
+        int after = genericItem.getQuality();
125
+        Assert.assertTrue(after == (before - 2));
126
+
127
+    }
128
+
129
+    @Test
130
+    public void neverNegativeTest() {
131
+        Inventory test = new Inventory(inventoryList);
132
+        agedbrietest.setQuality(0);
133
+        int before = agedbrietest.getQuality();
134
+        test.updateQuality();
135
+        int after = agedbrietest.getQuality();
136
+        Assert.assertTrue(after > 0);
137
+    }
138
+
139
+    @Test
140
+    public void agedBrieImprovesTest() {
141
+        Inventory test = new Inventory(inventoryList);
142
+        int before = agedbrietest.getQuality();
143
+        test.updateQuality();
144
+        int after = agedbrietest.getQuality();
145
+        Assert.assertTrue(after > before);
146
+    }
147
+
148
+    @Test
149
+    public void qualityNeverMoreThan50Test() {
150
+        Inventory test = new Inventory(inventoryList);
151
+        agedbrietest.setSellIn(0);
152
+        agedbrietest.setQuality(47);
153
+        int before = agedbrietest.getQuality();
154
+        test.updateQuality();
155
+        test.updateQuality();
156
+        test.updateQuality();
157
+        test.updateQuality();
158
+        test.updateQuality();
159
+        int after = agedbrietest.getQuality();
160
+        Assert.assertTrue(after == 50);
161
+    }
162
+
163
+    @Test
164
+    public void sulfurasNeverDegradesTest() {
165
+        Inventory test = new Inventory(inventoryList);
166
+        int before = sulfurastest.getQuality();
167
+        test.updateQuality();
168
+        int after = sulfurastest.getQuality();
169
+        Assert.assertTrue(before == after);
170
+    }
171
+
172
+    @Test
173
+    public void sulfurasNeverSellOutTest() {
174
+        Inventory test = new Inventory(inventoryList);
175
+
176
+        int before = sulfurastest.getSellIn();
177
+        test.updateQuality();
178
+
179
+        int after = sulfurastest.getSellIn();
180
+        Assert.assertTrue(after == before);
181
+    }
182
+
183
+    @Test
184
+    public void backStagePassQualityTest1() {
185
+        Inventory test = new Inventory(inventoryList);
186
+        backstagepasstest.setSellIn(9);
187
+        int before = backstagepasstest.getQuality();
188
+        int temp = backstagepasstest.getSellIn();
189
+        test.updateQuality();
190
+        int after = 0;
191
+        if (temp > 10) {
192
+            after=before+1;
193
+        }
194
+
195
+        if (temp <= 10) {
196
+            after = before + 2;
197
+        }
198
+
199
+        int expected = after;
200
+        int actual = backstagepasstest.getQuality();
201
+
202
+        Assert.assertEquals(expected,actual);
203
+    }
204
+
205
+    @Test
206
+    public void backStagePassQualityTest2() {
207
+        Inventory test = new Inventory(inventoryList);
208
+        backstagepasstest.setSellIn(4);
209
+        int before = backstagepasstest.getQuality();
210
+        int temp = backstagepasstest.getSellIn();
211
+        test.updateQuality();
212
+        int after = 0;
213
+        if (temp > 10) {
214
+            after=before+1;
215
+        }
216
+
217
+        if (temp <= 5) {
218
+            after = before + 3;
219
+        }
220
+
221
+        int expected = after;
222
+        int actual = backstagepasstest.getQuality();
223
+
224
+        Assert.assertEquals(expected,actual);
225
+    }
226
+
227
+    @Test
228
+    public void backStagePassQualityTest3() {
229
+        Inventory test = new Inventory(inventoryList);
230
+        backstagepasstest.setSellIn(0);
231
+        int before = backstagepasstest.getQuality();
232
+        int temp = backstagepasstest.getSellIn();
233
+        test.updateQuality();
234
+        int after = 0;
235
+        if (temp > 10) {
236
+            after=before+1;
237
+        }
238
+
239
+        if (temp <= 0) {
240
+            after = 0;
241
+        }
242
+
243
+        int expected = after;
244
+        int actual = backstagepasstest.getQuality();
245
+
246
+        Assert.assertEquals(expected,actual);
247
+    }
248
+
249
+
110 250
 }
111 251
 
252
+
253
+