Tommy Rogers 8 лет назад
Родитель
Сommit
de34d7e853
3 измененных файлов: 40 добавлений и 34 удалений
  1. 19
    27
      Inventory.java
  2. 14
    0
      InventoryTest.java
  3. 7
    7
      package.bluej

+ 19
- 27
Inventory.java Просмотреть файл

@@ -8,32 +8,24 @@ public class Inventory {
8 8
     }
9 9
 
10 10
     public void updateQuality() {
11
-        for (int i = 0; i < items.length; i++) {
12
-            if (!items[i].getName().equals("Aged Brie")) {
13
-                if (items[i].getQuality() > 0) {
14
-                    if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
15
-                        items[i].setQuality(items[i].getQuality() - 1);
16
-                    }
17
-                }
18
-            } else {
19
-                if (items[i].getQuality() < 50) {
20
-                    items[i].setQuality(items[i].getQuality() + 1);
21
-                }
22
-            }
23
-
24
-            if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
25
-                items[i].setSellIn(items[i].getSellIn() - 1);
26
-            }
27
-
28
-            if (items[i].getSellIn() < 0) {
29
-                if (!items[i].getName().equals("Aged Brie")) {
30
-                  items[i].setQuality(items[i].getQuality() - 1);
31
-                } else {
32
-                    if (items[i].getQuality() < 50) {
33
-                        items[i].setQuality(items[i].getQuality() + 1);
34
-                    }
35
-                }
36
-            }
11
+        for (Item item : items) {
12
+            String name = item.getName();
13
+            int currentQ = item.getQuality();
14
+            int currentS = item.getSellIn();
15
+            if(currentQ >0 && currentQ<50)
16
+                setQuality(name, item, currentQ, setSellIn(item, currentS, name));
37 17
         }
38
-}
18
+    }
19
+    public int setSellIn(Item item, int previousS, String name){
20
+        int newS = previousS -1;
21
+        item.setSellIn(newS);
22
+        int adjustment = (newS <= 0 || name.equals("Conjured"))? 2 : 1;
23
+        return adjustment;
24
+    }
25
+    public void setQuality(String name,Item item, int previousQ, int SellInAdjustment){
26
+        if(name.equals("Aged Brie"))
27
+            item.setQuality(previousQ + SellInAdjustment);
28
+        else
29
+            item.setQuality(previousQ - SellInAdjustment);
30
+    }
39 31
 }

+ 14
- 0
InventoryTest.java Просмотреть файл

@@ -11,11 +11,13 @@ public class InventoryTest {
11 11
 
12 12
     private Item sulfuras;
13 13
     private Item normalItem;
14
+    private Item conjuredItem;
14 15
 
15 16
     @Before
16 17
     public void setup(){
17 18
         sulfuras = new Item("Sulfuras, Hand of Ragnaros", 0, 80);
18 19
         normalItem = new Item(NORMAL_ITEM_NAME, 10, 20);
20
+        conjuredItem = new Item("Conjured", 10, 20);
19 21
     }
20 22
 
21 23
     @Test
@@ -49,6 +51,16 @@ public class InventoryTest {
49 51
 
50 52
         assertEquals(expectedSellIn, normalItem.getSellIn());
51 53
     }
54
+    @Test
55
+    public void testUpdate_ForConjuredItemQuantity() throws Exception {
56
+        int expectedQuality = conjuredItem.getQuality() - 2;
57
+        Item[] items = {conjuredItem};
58
+        Inventory sut = new Inventory(items);
59
+
60
+        sut.updateQuality();
61
+
62
+        assertEquals(expectedQuality, conjuredItem.getQuality());
63
+    }
52 64
 
53 65
     @Test
54 66
     public void testUpdate_ForNormalItemQuantity() throws Exception {
@@ -60,6 +72,8 @@ public class InventoryTest {
60 72
 
61 73
         assertEquals(expectedQuality, normalItem.getQuality());
62 74
     }
75
+    
76
+    
63 77
 
64 78
     @Test
65 79
     public void testUpdate_ForSoldOutItem() throws Exception {

+ 7
- 7
package.bluej Просмотреть файл

@@ -7,15 +7,15 @@ dependency2.to=Inventory
7 7
 dependency2.type=UsesDependency
8 8
 editor.fx.0.height=722
9 9
 editor.fx.0.width=800
10
-editor.fx.0.x=320
11
-editor.fx.0.y=50
10
+editor.fx.0.x=34
11
+editor.fx.0.y=32
12 12
 objectbench.height=164
13 13
 objectbench.width=776
14 14
 package.divider.horizontal=0.6
15 15
 package.divider.vertical=0.6845018450184502
16 16
 package.editor.height=364
17 17
 package.editor.width=674
18
-package.editor.x=577
18
+package.editor.x=480
19 19
 package.editor.y=61
20 20
 package.frame.height=600
21 21
 package.frame.width=800
@@ -41,13 +41,13 @@ target2.name=InventoryTest
41 41
 target2.showInterface=false
42 42
 target2.type=UnitTestTargetJunit4
43 43
 target2.width=80
44
-target2.x=40
45
-target2.y=160
44
+target2.x=90
45
+target2.y=180
46 46
 target3.association=InventoryTest
47 47
 target3.height=50
48 48
 target3.name=Inventory
49 49
 target3.showInterface=false
50 50
 target3.type=ClassTarget
51 51
 target3.width=80
52
-target3.x=10
53
-target3.y=190
52
+target3.x=60
53
+target3.y=210