|
@@ -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
|
|