Browse Source

Completed Lab

De'Jon Johnson 6 years ago
parent
commit
891aab5c62

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

@@ -9,6 +9,59 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
+    public void updateQuality(){
13
+        for(Item item : items){
14
+            String name = item.getName();
15
+            int sellin = item.getSellIn();
16
+            int quality = item.getQuality();
17
+            if(quality>=0 || quality<=50){
18
+                setQuality(name, item, quality, setSellin( name, sellin, item));
19
+            }
20
+        }
21
+    }
22
+
23
+    public void setQuality(String name, Item item, int quality, int sellinAdjustment){
24
+        if(name.equals("Aged Brie")) {
25
+            item.setQuality(quality+sellinAdjustment);
26
+        } else if(name.equals("Backstage passes to a TAFKAL80ETC concert")){
27
+            setQualityForPasses(item, quality);
28
+        }
29
+
30
+        else{
31
+            item.setQuality(quality-sellinAdjustment);
32
+        }
33
+    }
34
+    public int setSellin(String name,int sellin, Item item){
35
+        int newSellin = sellin -1;
36
+        item.setSellIn(newSellin);
37
+        int sellinAdjustment = (newSellin <= 0) ? 2 : 1;
38
+        return sellinAdjustment;
39
+    }
40
+    public void setQualityForPasses(Item item, int quality) {
41
+        int sellin = item.getSellIn();
42
+        int newSellin = sellin - 1;
43
+        item.setSellIn(newSellin);
44
+        if (newSellin <= 0) {
45
+            item.setQuality(0);
46
+        } else if (newSellin <= 5) {
47
+            item.setQuality(quality + 3);
48
+        } else if (newSellin <= 10) {
49
+            item.setQuality(quality + 2);
50
+        } else{
51
+            item.setQuality(quality+1);
52
+        }
53
+    }
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+/*(
12 65
 
13 66
     public void updateQuality() {
14 67
         for (int i = 0; i < items.length; i++) {
@@ -62,5 +115,6 @@ public class Inventory {
62 115
                 }
63 116
             }
64 117
         }
65
-    }
118
+
119
+    } */
66 120
 }

+ 104
- 2
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java View File

@@ -4,9 +4,111 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6 6
 public class InventoryTest {
7
+
8
+
9
+    @Test
10
+    public void updateQualityPt1() {
11
+
12
+        //Given
13
+        Item item1 = new Item("food", 2, 1);
14
+        Item item2 = new Item("food", 2, 1);
15
+        Item[] items = new Item[]{item1, item2};
16
+        //System.out.println(items);
17
+        Inventory unventory = new Inventory(items);
18
+        // when
19
+        unventory.updateQuality();
20
+        //Then
21
+        int actual = item1.getQuality();
22
+        int expected = 0;
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void updateQualityPt2() {
28
+        //Given
29
+        Item item1 = new Item("Backstage passes to a TAFKAL80ETC concert", 10, 46);
30
+        Item item2 = new Item("Backstage passes to a TAFKAL80ETC concert", 8, 39);
31
+        Item item3 = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 30);
32
+        Item[] items = new Item[]{item1, item2, item3};
33
+        Inventory newStuff = new Inventory(items);
34
+        //When
35
+        newStuff.updateQuality();
36
+
37
+        //Then
38
+        int actual = item1.getQuality();
39
+        int expected = 48;
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
7 43
     @Test
8
-    public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
44
+    public void updateQualityPt3() {
45
+        //Given
46
+        Item item1 = new Item("This is new name", -2,5);
47
+        Item item2 = new Item("Another name mayne", -6,10);
48
+        Item[] items = new Item[]{item1, item2};
49
+        Inventory otherStuff = new Inventory(items);
50
+
51
+        //When
52
+
53
+        otherStuff.updateQuality();
54
+
55
+        //Then
56
+        int actual = item1.getQuality();
57
+        int expected = 3;
58
+        Assert.assertEquals(expected, actual);
10 59
     }
60
+
61
+    @Test
62
+    public void updateQualityPt4() {
63
+        //Given
64
+        Item item1 = new Item("Aged Brie", -1, 41);
65
+        Item[] items = new Item[]{item1};
66
+        Inventory differentStuff = new Inventory(items);
67
+
68
+        //When
69
+
70
+        differentStuff.updateQuality();
71
+
72
+        //Then
73
+
74
+        int actual = item1.getQuality();
75
+        int expected = 43;
76
+        Assert.assertEquals(expected, actual);
77
+    }
78
+        @Test
79
+        public void updateQualityPt5() {
80
+            //Given
81
+        Item item1 = new Item ("Backstage passes to a TAFKAL80ETC concert", -2, 2);
82
+        Item[] items = new Item[]{item1};
83
+        Inventory finalVariable = new Inventory(items);
84
+
85
+            //When
86
+        finalVariable.updateQuality();
87
+            //Then
88
+            int actual = item1.getQuality();
89
+            int expected = 0;
90
+            Assert.assertEquals(expected, actual);
91
+
92
+        }
93
+
94
+    @Test
95
+    public void updateQualityPt6() {
96
+        //Given
97
+        Item item1 = new Item("Backstage passes to a TAFKAL80ETC concert", -2, 2);
98
+        Item[] items = new Item[]{item1};
99
+        Inventory variable = new Inventory(items);
100
+
101
+        //When
102
+        item1.setName("Final Name");
103
+
104
+        //Then
105
+        String expected = "Final Name";
106
+        String actual = item1.getName();
107
+        Assert.assertEquals(expected, actual);
108
+
109
+    }
110
+
111
+
11 112
 }
12 113
 
114
+