Browse Source

Completed parts one and two.

William Brown 6 years ago
parent
commit
32378515e0

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

@@ -9,56 +9,39 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
+    public void updateQuality(){
13
+        agedBrie();
14
+        sulfuras();
15
+        backstagePasses();
16
+    }
12 17
 
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) {
18
+    public void agedBrie(){
19
+        for(int i = 0; i < items.length; i++){
20
+            if(items[i].getName().equals("Aged Brie") && items[i].getQuality() < 50) {
24 21
                     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 22
             }
23
+        }
24
+    }
41 25
 
42
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
43
-                items[i].setSellIn(items[i].getSellIn() - 1);
26
+    public void sulfuras(){
27
+        for(int i = 0; i < items.length; i++){
28
+            if(items[i].getName().equals("Sulfuras, Hand of Ragnaros") && items[i].getQuality() < 80){
29
+                continue;
44 30
             }
31
+        }
32
+    }
45 33
 
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
-                    }
34
+    public void backstagePasses(){
35
+        for(int i = 0; i < items.length; i++) {
36
+            if(items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
37
+                if(items[i].getSellIn() < 0){
38
+                    items[i].setQuality(0);
39
+                }else if(items[i].getSellIn() <= 5 && items[i].getQuality() < 48){
40
+                    items[i].setQuality(items[i].getQuality() + 3);
41
+                }else if(items[i].getSellIn() <= 10 && items[i].getQuality() < 49){
42
+                    items[i].setQuality(items[i].getQuality() + 2);
43
+                }else if(items[i].getSellIn() > 10 && items[i].getQuality() < 50){
44
+                    items[i].setQuality(items[i].getQuality() + 1);
62 45
                 }
63 46
             }
64 47
         }

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

@@ -3,10 +3,108 @@ package com.zipcodewilmington.gildedrose;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
+import java.util.ArrayList;
7
+
6 8
 public class InventoryTest {
9
+
10
+    @Test
11
+    public void testAgedBrie1() {
12
+        Item agedBrie = new Item("Aged Brie", 10, 10);
13
+        Item[] item = {agedBrie};
14
+        Inventory inventory = new Inventory(item);
15
+        inventory.updateQuality();
16
+        int expected = 11;
17
+        int actual = agedBrie.getQuality();
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void testAgedBrie2() {
23
+        Item agedBrie = new Item("Aged Brie", 10, 49);
24
+        Item[] item = {agedBrie};
25
+        Inventory inventory = new Inventory(item);
26
+        inventory.updateQuality();
27
+        int expected = 50;
28
+        int actual = agedBrie.getQuality();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void testAgedBrie3() {
34
+        Item agedBrie = new Item("Aged Brie", 10, 50);
35
+        Item[] item = {agedBrie};
36
+        Inventory inventory = new Inventory(item);
37
+        inventory.updateQuality();
38
+        int expected = 50;
39
+        int actual = agedBrie.getQuality();
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void testBackstagePass1() {
45
+        Item backstage = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 40);
46
+        Item[] item = {backstage};
47
+        Inventory inventory = new Inventory(item);
48
+        inventory.updateQuality();
49
+        int expected = 41;
50
+        int actual = backstage.getQuality();
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
7 54
     @Test
8
-    public void updateQuantityTest(){
9
-        Assert.assertEquals(1, 1);
55
+    public void testBackstagePass2() {
56
+        Item backstage = new Item("Backstage passes to a TAFKAL80ETC concert", 7, 40);
57
+        Item[] item = {backstage};
58
+        Inventory inventory = new Inventory(item);
59
+        inventory.updateQuality();
60
+        int expected = 42;
61
+        int actual = backstage.getQuality();
62
+        Assert.assertEquals(expected, actual);
10 63
     }
64
+
65
+    @Test
66
+    public void testBackstagePass3() {
67
+        Item backstage = new Item("Backstage passes to a TAFKAL80ETC concert", 3, 40);
68
+        Item[] item = {backstage};
69
+        Inventory inventory = new Inventory(item);
70
+        inventory.updateQuality();
71
+        int expected = 43;
72
+        int actual = backstage.getQuality();
73
+        Assert.assertEquals(expected, actual);
74
+    }
75
+
76
+    @Test
77
+    public void testBackstagePass4() {
78
+        Item backstage = new Item("Backstage passes to a TAFKAL80ETC concert", 0, 40);
79
+        Item[] item = {backstage};
80
+        Inventory inventory = new Inventory(item);
81
+        inventory.updateQuality();
82
+        int expected = 43;
83
+        int actual = backstage.getQuality();
84
+        Assert.assertEquals(expected, actual);
85
+    }
86
+
87
+    @Test
88
+    public void testBackstagePass5() {
89
+        Item backstage = new Item("Backstage passes to a TAFKAL80ETC concert", -1, 40);
90
+        Item[] item = {backstage};
91
+        Inventory inventory = new Inventory(item);
92
+        inventory.updateQuality();
93
+        int expected = 0;
94
+        int actual = backstage.getQuality();
95
+        Assert.assertEquals(expected, actual);
96
+    }
97
+
98
+    @Test
99
+    public void testSulfurasPass1() {
100
+        Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 10, 40);
101
+        Item[] item = {sulfuras};
102
+        Inventory inventory = new Inventory(item);
103
+        inventory.updateQuality();
104
+        int expected = 40;
105
+        int actual = sulfuras.getQuality();
106
+        Assert.assertEquals(expected, actual);
107
+    }
108
+
11 109
 }
12 110