Browse Source

Added conjured items

Jonathan Hinds 6 years ago
parent
commit
df7b266a40

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

@@ -9,58 +9,143 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
+//    public void updateQuality() {
13
+//        //for each item in the inventory
14
+//        for (int i = 0; i < items.length; i++) {
15
+//
16
+//            //if the items name not equal aged brie and the items name does not equal Backstage passes to a TAFKAL80ETC concert and the items quality is greater than 0, and the items name does not equal Sulfuras, Hand of Ragnaros
17
+//            if (!items[i].getName().equals("Aged Brie") && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert") && items[i].getQuality() > 0 && !items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
18
+//                //decrease quality by one
19
+//                items[i].setQuality(items[i].getQuality() - 1);
20
+//                //if the items name is "Aged Brie", "Backstage passes to a TAFKAL80ETC concert" or "Sulfuras, Hand of Ragnaros", and the quality is between 0 and 50
21
+//            } else if(items[i].getQuality() < 50){
22
+//                //increase item quality by one
23
+//                items[i].setQuality(items[i].getQuality() + 1);
24
+//                //if the item is "Backstage passes to a TAFKAL80ETC concert" and the item sells in less than 11 days
25
+//                if (items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert") && items[i].getSellIn() < 11) {
26
+//                    //increase item quality by one
27
+//                    items[i].setQuality(items[i].getQuality() + 1);
28
+//                    //if the item sells in less than 6 days
29
+//                    if (items[i].getSellIn() < 6) {
30
+//                        //increase item quality by another one
31
+//                        items[i].setQuality(items[i].getQuality() + 1);
32
+//                    }
33
+//                }
34
+//            }
35
+//            //if the item is past its expiration date
36
+//            if (items[i].getSellIn() < 0 ) {
37
+//                //and it is not aged brie
38
+//                if (!items[i].getName().equals("Aged Brie")) {
39
+//                    //if the item name is not "Backstage passes to a TAFKAL80ETC concert" and the quality is greater than 0
40
+//                    if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert") && items[i].getQuality() > 0) {
41
+//                        //if the item name is "Sulfuras, Hand of Ragnaros"
42
+//                        if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
+//                            //decrease the item quality by one
44
+//                            items[i].setQuality(items[i].getQuality() - 1);
45
+//                        }
46
+//                        //if the item is not "Backstage passes to a TAFKAL80ETC concert" and the quality is greater than 0
47
+//                    } else {
48
+//                        //set item quality to 0
49
+//                        items[i].setQuality(0);
50
+//                    }
51
+//                    //if the item is not named aged brie
52
+//                } else {
53
+//                    //and it is less than 50 quality
54
+//                    if (items[i].getQuality() < 50) {
55
+//                        //increase the quality by one
56
+//                        items[i].setQuality(items[i].getQuality() + 1);
57
+//                    }
58
+//                }
59
+//            }
60
+//        }
61
+//    }
12 62
 
13
-    public void updateQuality() {
14
-        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
-                        }
38
-                    }
39
-                }
63
+    public void updateQuality02() {
64
+
65
+        for(int i = 0; i < items.length; i ++){
66
+
67
+            switch(items[i].getName()){
68
+
69
+                case "Aged Brie":
70
+                    increaseQuality(items[i]);
71
+                    passedSellin(items[i]);
72
+                    break;
73
+
74
+                case "Backstage passes to a TAFKAL80ETC concert":
75
+                    increaseQuality(items[i]);
76
+                    checkSellinTickets(items[i]);
77
+                    passedSellin(items[i]);
78
+                    break;
79
+
80
+                case "Sulfuras, Hand of Ragnaros":
81
+                    break;
82
+
83
+                case "Conjured Item":
84
+                    decreaseQuality(items[i]);
85
+                    decreaseQuality(items[i]);
86
+                    passedSellin(items[i]);
87
+                    break;
88
+
89
+                default:
90
+                    decreaseQuality(items[i]);
91
+                    passedSellin(items[i]);
92
+                    break;
40 93
             }
94
+        }
95
+    }
96
+
97
+    private static void increaseQuality(Item item){
98
+        if(item.getQuality() < 50){
99
+            item.setQuality(item.getQuality() + 1);
100
+        }
101
+    }
41 102
 
42
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
-                items[i].setSellIn(items[i].getSellIn() - 1);
103
+    private static void decreaseQuality(Item item){
104
+        if(item.getQuality() > 0){
105
+            item.setQuality(item.getQuality() -1);
106
+        }
107
+    }
108
+
109
+    private static void checkSellinTickets(Item item){
110
+        //if the items sell in is less then 11
111
+        if(item.getSellIn() < 11){
112
+            //decrease quality
113
+            increaseQuality(item);
114
+            //if it is also less then 6
115
+            if(item.getSellIn() < 6){
116
+                //decrease quality
117
+                increaseQuality(item);
44 118
             }
119
+        }
120
+    }
121
+
122
+    private static void passedSellin(Item item){
123
+        switch(item.getName()) {
124
+            case "Aged Brie":
125
+                increaseQuality(item);
126
+                break;
45 127
 
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
-                    }
128
+            case "Backstage passes to a TAFKAL80ETC concert":
129
+                if(item.getSellIn() < 0) {
130
+                    item.setQuality(0);
62 131
                 }
63
-            }
132
+                break;
133
+
134
+            case "Conjured Item":
135
+                checkPassedDate(item);
136
+                checkPassedDate(item);
137
+                break;
138
+
139
+            default:
140
+                checkPassedDate(item);
141
+                break;
142
+        }
143
+    }
144
+
145
+    private static void checkPassedDate(Item item){
146
+        if(item.getSellIn() < 0){
147
+            decreaseQuality(item);
64 148
         }
65 149
     }
150
+
66 151
 }

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

@@ -4,9 +4,95 @@ import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6 6
 public class InventoryTest {
7
+
7 8
     @Test
8 9
     public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
10
+        //test item that should go down 1 quality in 1 day
11
+        Item item = new Item("A book", 12, 20);
12
+        Item[] items = {item};
13
+
14
+        Inventory inv = new Inventory(items);
15
+        inv.updateQuality02();
16
+        Assert.assertEquals(19, item.getQuality());
17
+    }
18
+
19
+    @Test
20
+    public void updateQuantityTest02(){
21
+        //test item that should go down two quality in 1 day
22
+        Item item = new Item("A book", -1, 20);
23
+        Item[] items = {item};
24
+
25
+        Inventory inv = new Inventory(items);
26
+        inv.updateQuality02();
27
+        System.out.println(item.getQuality());
28
+        Assert.assertEquals(18, item.getQuality());
29
+    }
30
+
31
+    @Test
32
+    public void updateQuantityTest03(){
33
+        //test aged brie that should increase in quality twice
34
+        Item item = new Item("Aged Brie", -1, 15);
35
+        Item[] items = {item};
36
+
37
+        Inventory inv = new Inventory(items);
38
+        inv.updateQuality02();
39
+        Assert.assertEquals(17, item.getQuality());
40
+    }
41
+
42
+    @Test
43
+    public void updateQuantityTest04() {
44
+        //test that tickets for TAFKAL80ETC goes up three times
45
+        Item item = new Item("Backstage passes to a TAFKAL80ETC concert", 5, 15);
46
+        Item[] items = {item};
47
+
48
+        Inventory inv = new Inventory(items);
49
+        inv.updateQuality02();
50
+        Assert.assertEquals(18, item.getQuality());
10 51
     }
11
-}
12 52
 
53
+    @Test
54
+    public void updateQuantityTest05() {
55
+        //test that tickets for TAFKAL80ETC goes up three times
56
+        Item item = new Item("Aged Brie", 0, 15);
57
+        item.setName("A book");
58
+        item.setSellIn(50);
59
+        Item[] items = {item};
60
+
61
+        Inventory inv = new Inventory(items);
62
+        inv.updateQuality02();
63
+        Assert.assertEquals(14, item.getQuality());
64
+    }
65
+
66
+    @Test
67
+    public void updateQuantityTest06() {
68
+        //test that tickets for TAFKAL80ETC goes up three times
69
+        Item item = new Item("Backstage passes to a TAFKAL80ETC concert", -3, 15);
70
+        Item[] items = {item};
71
+
72
+        Inventory inv = new Inventory(items);
73
+        inv.updateQuality02();
74
+        Assert.assertEquals(0, item.getQuality());
75
+    }
76
+
77
+    @Test
78
+    public void updateQuantityTest07() {
79
+        //test that tickets for TAFKAL80ETC goes up three times
80
+        Item item = new Item("Sulfuras, Hand of Ragnaros", 0, 15);
81
+        Item[] items = {item};
82
+
83
+        Inventory inv = new Inventory(items);
84
+        inv.updateQuality02();
85
+        Assert.assertEquals(15, item.getQuality());
86
+    }
87
+
88
+    @Test
89
+    public void updateQuantityTest08() {
90
+        //test that tickets for TAFKAL80ETC goes up three times
91
+        Item item = new Item("Conjured Item", -1, 15);
92
+        Item[] items = {item};
93
+
94
+        Inventory inv = new Inventory(items);
95
+        inv.updateQuality02();
96
+        Assert.assertEquals(11, item.getQuality());
97
+    }
98
+}