Parcourir la source

Added a whole test to the ONE GIANT METHOD of Inventory Class

Trinh Tong il y a 6 ans
Parent
révision
440b0870ad

+ 15
- 0
src/main/java/com/zipcodewilmington/gildedrose/Inventory.java Voir le fichier

@@ -9,7 +9,22 @@ public class Inventory {
9 9
         this.items = items;
10 10
     }
11 11
 
12
+//    public void increaseQuality(int i){
13
+//
14
+//        int quality = item.getQuality() + i;
15
+//        if (quality > 50) {
16
+//            quality = 50;
17
+//        }
18
+//
19
+//        item.setQuality(quality);
20
+//    }
21
+
22
+    public Item[] getItems(){
23
+        return this.items;
24
+    }
25
+
12 26
 
27
+    // Old Code
13 28
     public void updateQuality() {
14 29
         // Giant for loop representing the "day" each day, the quality's of items change.
15 30
 

+ 61
- 2
src/test/java/com/zipcodewilmington/gildedrose/InventoryTest.java Voir le fichier

@@ -3,6 +3,8 @@ package com.zipcodewilmington.gildedrose;
3 3
 import org.junit.Assert;
4 4
 import org.junit.Test;
5 5
 
6
+import java.util.Arrays;
7
+
6 8
 /**
7 9
  * Creating tests for the Inventory Class
8 10
  * The Inventory class will keep track of SellIn & Quality
@@ -10,9 +12,66 @@ import org.junit.Test;
10 12
  */
11 13
 
12 14
 public class InventoryTest {
15
+    Inventory inventory;
16
+
17
+    public InventoryTest() {
18
+
19
+        Item wine = new Item("wine", 2, 25);
20
+        Item agedBrie = new Item("Aged Brie", 1, 45);
21
+        Item passes = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 25);
22
+        Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 10, 80 );
23
+
24
+        Item[] items = {wine, agedBrie, passes, sulfuras};
25
+
26
+        inventory = new Inventory(items);
27
+    }
28
+
29
+    public void assertTestValues(Inventory inventory, int days, int wineSellIn, int wineQuality, int brieSellIn, int brieQuality,
30
+                                 int passSellIn, int passQuality, int sulfurasSellIn, int sulfurasQuality) {
31
+        for (int i = 0; i < days; i++) {
32
+            inventory.updateQuality();
33
+        }
34
+        Item[] items = inventory.getItems();
35
+        Item currentItem = items[0];
36
+        Assert.assertSame("wine", currentItem.getName());
37
+        Assert.assertEquals(wineSellIn, currentItem.getSellIn());
38
+        Assert.assertEquals(wineQuality, currentItem.getQuality());
39
+
40
+        currentItem = items[1];
41
+        Assert.assertSame("Aged Brie", currentItem.getName());
42
+        Assert.assertEquals(brieSellIn, currentItem.getSellIn());
43
+        Assert.assertEquals(brieQuality, currentItem.getQuality());
44
+
45
+        currentItem = items[2];
46
+        Assert.assertSame("Backstage passes to a TAFKAL80ETC concert", currentItem.getName());
47
+        Assert.assertEquals(passSellIn, currentItem.getSellIn());
48
+        Assert.assertEquals(passQuality, currentItem.getQuality());
49
+
50
+        currentItem = items[3];
51
+        Assert.assertSame("Sulfuras, Hand of Ragnaros", currentItem.getName());
52
+        Assert.assertEquals(sulfurasSellIn, currentItem.getSellIn());
53
+        Assert.assertEquals(sulfurasQuality, currentItem.getQuality());
54
+    }
55
+
13 56
     @Test
14
-    public void updateQuantityTest(){
15
-        Assert.assertEquals(1, 1);
57
+    public void updateQualityTest(){
58
+        // Given
59
+
60
+        // One day
61
+        assertTestValues(inventory, 1, 1, 24, 0, 46, 10, 26, 10, 80);
62
+
63
+        // One more day
64
+        assertTestValues(inventory, 1, 0, 23, -1, 48, 9, 28, 10, 80);
65
+
66
+        // Four more days
67
+        assertTestValues(inventory, 4, -4, 15, -5, 50, 5, 36, 10, 80);
68
+
69
+        // Three more days
70
+        assertTestValues(inventory, 3, -7, 9, -8, 50, 2, 45, 10, 80);
71
+
72
+        // Five more days
73
+        assertTestValues(inventory, 5, -12, 0, -13, 50, -3, 0, 10, 80);
16 74
     }
75
+
17 76
 }
18 77
 

+ 9
- 0
src/test/java/com/zipcodewilmington/gildedrose/ItemTest.java Voir le fichier

@@ -0,0 +1,9 @@
1
+package com.zipcodewilmington.gildedrose;
2
+
3
+import org.junit.Test;
4
+
5
+// test item class
6
+
7
+public class ItemTest {
8
+
9
+}