Brandon Defrancis 6 лет назад
Родитель
Сommit
feebd55637

+ 137
- 45
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Просмотреть файл

@@ -9,58 +9,150 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
-
13
-    public void updateQuality() {
12
+    public void qualityUpdate() {
14 13
         for (int i = 0; i < items.length; i++) {
15
-            if (!items[i].getName().equals("Aged Brie")
16
-                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
17
-                if (items[i].getQuality() > 0) {
18
-                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
19
-                        items[i].setQuality(items[i].getQuality() - 1);
20
-                    }
21
-                }
22
-            } else {
23
-                if (items[i].getQuality() < 50) {
24
-                    items[i].setQuality(items[i].getQuality() + 1);
25
-
26
-                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
27
-                        if (items[i].getSellIn() < 11) {
28
-                            if (items[i].getQuality() < 50) {
29
-                                items[i].setQuality(items[i].getQuality() + 1);
30
-                            }
31
-                        }
32
-
33
-                        if (items[i].getSellIn() < 6) {
34
-                            if (items[i].getQuality() < 50) {
35
-                                items[i].setQuality(items[i].getQuality() + 1);
36
-                            }
37
-                        }
14
+
15
+            switch (items[i].getName()) {
16
+
17
+                case "A book":
18
+                    if (items[i].getQuality() > 0) {
19
+                        items[i].setQuality(items[i].getQuality() - 2);
20
+                        break;
38 21
                     }
39
-                }
22
+
23
+                case "Aged Brie":
24
+                    increaseQuality(items[i]);
25
+                    increaseQuality(items[i]);
26
+                    break;
27
+
28
+                case "Backstage passes to a TAFKAL80ETC concert":
29
+                    increaseQuality(items[i]);
30
+                    checkSellIn(items[i]);
31
+                    overSellIn(items[i]);
32
+                    break;
33
+
34
+                case "Sulfuras, Hand of Ragnaros":
35
+                    break;
36
+
37
+                case "Conjuring":
38
+                    decreaseQuality(items[i]);
39
+                    items[i].setQuality(items[i].getQuality() - 3);
40
+                    overSellIn(items[i]);
41
+                    break;
42
+
43
+                default:
44
+                    decreaseQuality(items[i]);
45
+                    checkOverSellIn(items[i]);
46
+
40 47
             }
41 48
 
42
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
-                items[i].setSellIn(items[i].getSellIn() - 1);
49
+        }
50
+    }
51
+
52
+
53
+        public static void increaseQuality(Item item){
54
+            if (item.getQuality() < 50) {
55
+                item.setQuality(item.getQuality() + 1);
56
+
44 57
             }
58
+        }
59
+            public static void decreaseQuality(Item item){
60
+            if (item.getQuality() > 0) {
61
+                item.setQuality(item.getQuality() - 1);
45 62
 
46
-            if (items[i].getSellIn() < 0) {
47
-                if (!items[i].getName().equals("Aged Brie")) {
48
-                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
49
-                        if (items[i].getQuality() > 0) {
50
-                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
51
-                                items[i].setQuality(items[i].getQuality() - 1);
52
-                            }
53
-                        }
54
-                    } else {
55
-                        items[i].setQuality(items[i].getQuality()
56
-                                - items[i].getQuality());
57
-                    }
58
-                } else {
59
-                    if (items[i].getQuality() < 50) {
60
-                        items[i].setQuality(items[i].getQuality() + 1);
61
-                    }
62
-                }
63 63
             }
64 64
         }
65
+
66
+    public static void checkSellIn(Item item) {
67
+        if (item.getSellIn() < 11) {
68
+            increaseQuality(item);
69
+        }
70
+        if (item.getSellIn() < 6) {
71
+            increaseQuality(item);
72
+        }
73
+    }
74
+
75
+    public static void checkOverSellIn(Item item){
76
+        if (item.getQuality() < 0) {
77
+            decreaseQuality(item);
78
+        }
79
+    }
80
+
81
+    public static void overSellIn(Item item){
82
+        switch (item.getName()) {
83
+            case "Aged Brie":
84
+                increaseQuality(item);
85
+                break;
86
+
87
+            case "Backstage passes to a TAFKAL80ETC concert":
88
+                if(item.getQuality() < 0) {
89
+                    item.setQuality(0);
90
+                }
91
+                break;
92
+
93
+            case "Conjuring":
94
+                checkOverSellIn(item);
95
+                break;
96
+
97
+            default:
98
+                checkOverSellIn(item);
99
+                break;
100
+        }
101
+
102
+
65 103
     }
104
+
105
+//    public void updateQuality() {
106
+//        for (int i = 0; i < items.length; i++) {
107
+//            if (!items[i].getName().equals("Aged Brie")
108
+//                    && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
109
+//                if (items[i].getQuality() > 0) {
110
+//                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
111
+//                        items[i].setQuality(items[i].getQuality() - 1);
112
+//                    }
113
+//                }
114
+//            } else {
115
+//                if (items[i].getQuality() < 50) {
116
+//                    items[i].setQuality(items[i].getQuality() + 1);
117
+//
118
+//                    if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
119
+//                        if (items[i].getSellIn() < 11) {
120
+//                            if (items[i].getQuality() < 50) {
121
+//                                items[i].setQuality(items[i].getQuality() + 1);
122
+//                            }
123
+//                        }
124
+//
125
+//                        if (items[i].getSellIn() < 6) {
126
+//                            if (items[i].getQuality() < 50) {
127
+//                                items[i].setQuality(items[i].getQuality() + 1);
128
+//                            }
129
+//                        }
130
+//                    }
131
+//                }
132
+//            }
133
+//
134
+//            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
135
+//                items[i].setSellIn(items[i].getSellIn() - 1);
136
+//            }
137
+//
138
+//            if (items[i].getSellIn() < 0) {
139
+//                if (!items[i].getName().equals("Aged Brie")) {
140
+//                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
141
+//                        if (items[i].getQuality() > 0) {
142
+//                            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
143
+//                                items[i].setQuality(items[i].getQuality() - 1);
144
+//                            }
145
+//                        }
146
+//                    } else {
147
+//                        items[i].setQuality(items[i].getQuality()
148
+//                                - items[i].getQuality());
149
+//                    }
150
+//                } else {
151
+//                    if (items[i].getQuality() < 50) {
152
+//                        items[i].setQuality(items[i].getQuality() + 1);
153
+//                    }
154
+//                }
155
+//            }
156
+//        }
157
+//    }
66 158
 }

+ 66
- 1
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Просмотреть файл

@@ -5,8 +5,73 @@ import org.junit.Test;
5 5
 
6 6
 public class InventoryTest {
7 7
     @Test
8
-    public void updateQuantityTest(){
8
+    public void updateQuantityTest() {
9
+
10
+
9 11
         Assert.assertEquals(1, 1);
12
+
13
+        Item item = new Item("A book", 12, 20);
14
+        Item[] items = {item};
15
+
16
+        Inventory inv = new Inventory(items);
17
+        inv.qualityUpdate();
18
+        System.out.println(item.getQuality());
19
+        Assert.assertEquals(18, item.getQuality());
20
+
21
+    }
22
+
23
+    @Test
24
+    public void updateQuantityTest2() {
25
+
26
+        Item item = new Item("Aged Brie", -1, 15);
27
+        Item[] items = {item};
28
+
29
+        Inventory inv = new Inventory(items);
30
+        inv.qualityUpdate();
31
+        System.out.println(item.getQuality());
32
+        Assert.assertEquals(17, item.getQuality());
33
+
10 34
     }
35
+
36
+    @Test
37
+    public void updateQuantityTest3() {
38
+
39
+        Item item = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 15);
40
+        Item[] items = {item};
41
+
42
+        Inventory inv = new Inventory(items);
43
+        inv.qualityUpdate();
44
+        System.out.println(item.getQuality());
45
+        Assert.assertEquals(18, item.getQuality());
46
+
47
+    }
48
+
49
+    @Test
50
+    public void updateQuantityTest4() {
51
+
52
+        Item item = new Item("Sulfuras, Hand of Ragnaros", 0, 15);
53
+        Item[] items = {item};
54
+
55
+        Inventory inv = new Inventory(items);
56
+        inv.qualityUpdate();
57
+
58
+        System.out.println(item.getQuality());
59
+        Assert.assertEquals(15, item.getQuality());
60
+
61
+    }
62
+
63
+    @Test
64
+    public void updateQuantityTest5() {
65
+
66
+        Item item = new Item("Conjuring", -1, 15);
67
+        Item[] items = {item};
68
+
69
+        Inventory inv = new Inventory(items);
70
+        inv.qualityUpdate();
71
+        System.out.println(item.getQuality());
72
+        Assert.assertEquals(11, item.getQuality());
73
+
74
+    }
75
+
11 76
 }
12 77