Bläddra i källkod

I'm actually pretty proud of myself for finishing this

Whitney Martinez 6 år sedan
förälder
incheckning
74787d2bb1

+ 94
- 47
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Visa fil

@@ -3,64 +3,111 @@ package com.zipcodewilmington.gildedrose;
3 3
 
4 4
 public class Inventory {
5 5
     private Item[] items;
6
+    static final String Aged = "Aged Brie";
7
+    static final String Backstage = "Backstage passes to a TAFKAL80ETC concert";
8
+    static final String Sulf = "Sulfuras,Hand of Ragnaros";
9
+    static final String Conj = "Conjured";
6 10
 
7 11
     public Inventory(Item[] items) {
8 12
         super();
9 13
         this.items = items;
10 14
     }
11 15
 
16
+    public void refactor() {
12 17
 
13
-    public void updateQuality() {
14 18
         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
-                }
40
-            }
41 19
 
42
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
-                items[i].setSellIn(items[i].getSellIn() - 1);
20
+            switch (items[i].getName()) {
21
+
22
+                case Aged:
23
+                    increaseQuality(items[i]);
24
+                    under6days(items[i]);
25
+                    expireditems(items[i]);
26
+                    sulferus_Deduction(items[i]);
27
+
28
+                    break;
29
+
30
+                case Backstage:
31
+                    increaseQuality(items[i]);
32
+                    extramoneyfortheconcert(items[i]);
33
+                    sulferus_Deduction(items[i]);
34
+                    expireditems(items[i]);
35
+                    break;
36
+
37
+                case Sulf:
38
+                    increaseQuality(items[i]);
39
+                    under6days(items[i]);
40
+                    expireditems(items[i]);
41
+                    break;
42
+
43
+
44
+                case Conj:
45
+
46
+                    notFromTheOriginalList(items[i]);
47
+                    sulferus_Deduction(items[i]);
48
+
49
+                    break;
50
+
51
+                    default:
52
+
53
+                        notFromTheOriginalList(items[i]);
54
+                        sulferus_Deduction(items[i]);
44 55
             }
56
+        }
57
+    }
58
+
59
+
60
+    public void increaseQuality(Item item){
61
+
62
+        if(item.getQuality() < 50 ){
63
+            item.setQuality(item.getQuality()+1);
64
+
65
+        }
66
+    }
67
+    public void expireditems(Item item){
68
+
69
+        if(item.getSellIn()< 0) {
70
+            item.setQuality(0);
71
+        }
72
+
73
+    }
74
+    public void under6days(Item item){
75
+
76
+        if(item.getSellIn()<6 && item.getQuality()<50){
77
+
78
+            item.setQuality(item.getQuality()+1);
79
+        }
80
+
81
+    }
82
+
83
+    public void extramoneyfortheconcert(Item item){
84
+
85
+        if(item.getSellIn()<11 && item.getQuality()<50){
86
+
87
+            item.setQuality(item.getQuality()+1);
88
+
89
+        }
90
+
91
+    }
92
+    public void sulferus_Deduction(Item item){
93
+
94
+        if(!Sulf.equals(item)){
95
+
96
+            item.setSellIn(item.getSellIn()-1);
97
+
98
+        }
99
+    }
100
+
101
+    public void notFromTheOriginalList(Item item){
102
+
103
+            if(!item.equals(Sulf)&&!item.equals(Aged)&&!item.equals(Backstage)){
104
+
105
+                item.setQuality(item.getQuality()-2);
45 106
 
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 107
             }
108
+
109
+
64 110
         }
111
+
65 112
     }
66
-}
113
+

+ 82
- 1
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Visa fil

@@ -6,7 +6,88 @@ import org.junit.Test;
6 6
 public class InventoryTest {
7 7
     @Test
8 8
     public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
9
+
10
+        Item item = new Item("Aged Brie",4,10);
11
+        Item[] items = {item};
12
+
13
+
14
+        Assert.assertEquals(18, item.getQuality());
15
+    }
16
+    @Test
17
+    public void UpdatingQualities() {
18
+        Item backstagePass = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 30);
19
+        Item arr[] = new Item[1];
20
+        arr[0] = backstagePass;
21
+        Inventory inventory = new Inventory(arr);
22
+        int expectedOutput = 0;
23
+
24
+        //when
25
+        inventory.refactor();
26
+        int actualOutput = backstagePass.getQuality();
27
+
28
+        //then
29
+        Assert.assertEquals(expectedOutput, actualOutput);
30
+               }
31
+    @Test
32
+    public void UpdatingQualities2() {
33
+        Item aged = new Item("aged", -1, 9);
34
+        Item arr[] = new Item[1];
35
+        arr[0] = aged;
36
+        Inventory inventory = new Inventory(arr);
37
+        int expectedOutput = 0;
38
+
39
+        //when
40
+        inventory.refactor();
41
+        int actualOutput = aged.getQuality();
42
+
43
+        //then
44
+        Assert.assertEquals(expectedOutput, actualOutput);
10 45
     }
46
+    @Test
47
+    public void UpdatingSelldates() {
48
+        Item concert = new Item("Backstage passes to a TAFKAL80ETC concert", 10, 9);
49
+        Item arr[] = new Item[1];
50
+        arr[0] = concert;
51
+        Inventory inventory = new Inventory(arr);
52
+        int expectedOutput = 9;
53
+
54
+        //when
55
+        inventory.refactor();
56
+        int actualOutput = concert.getSellIn();
57
+
58
+        //then
59
+        Assert.assertEquals(expectedOutput, actualOutput);
60
+    }
61
+    @Test
62
+    public void Notfromtheoriginallist() {
63
+        Item apple = new Item("apple", -1, 9);
64
+        Item arr[] = new Item[1];
65
+        arr[0] = apple;
66
+        Inventory inventory = new Inventory(arr);
67
+        int expectedOutput = 0;
68
+
69
+        //when
70
+        inventory.refactor();
71
+        int actualOutput = apple.getQuality();
72
+
73
+        //then
74
+        Assert.assertEquals(expectedOutput, actualOutput);
75
+    }
76
+    @Test
77
+    public void Notfromtheoriginallist2() {
78
+        Item apple = new Item("Conjured", 10, 90);
79
+        Item arr[] = new Item[1];
80
+        arr[0] = apple;
81
+        Inventory inventory = new Inventory(arr);
82
+        int expectedOutput = 88;
83
+
84
+        //when
85
+        inventory.refactor();
86
+        int actualOutput = apple.getQuality();
87
+
88
+        //then
89
+        Assert.assertEquals(expectedOutput, actualOutput);
90
+    }
91
+
11 92
 }
12 93