|
@@ -14,64 +14,98 @@ import java.util.Arrays;
|
14
|
14
|
public class InventoryTest {
|
15
|
15
|
Inventory inventory;
|
16
|
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 );
|
|
17
|
+ Item wine = new Item("wine", 2, 25);
|
|
18
|
+ Item agedBrie = new Item("Aged Brie", 1, 45);
|
|
19
|
+ Item passes = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 25);
|
|
20
|
+ Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 10, 80 );
|
23
|
21
|
|
24
|
|
- Item[] items = {wine, agedBrie, passes, sulfuras};
|
|
22
|
+ Item[] items = {wine, agedBrie, passes, sulfuras};
|
25
|
23
|
|
|
24
|
+ public InventoryTest() {
|
26
|
25
|
inventory = new Inventory(items);
|
27
|
26
|
}
|
28
|
27
|
|
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
|
|
-
|
56
|
28
|
@Test
|
57
|
|
- public void updateQualityTest(){
|
|
29
|
+ public void testBrieQuality() {
|
|
30
|
+ // Brie quality increases as sell in decreases
|
58
|
31
|
// Given
|
59
|
32
|
|
60
|
|
- // One day
|
61
|
|
- assertTestValues(inventory, 1, 1, 24, 0, 46, 10, 26, 10, 80);
|
|
33
|
+ int expectedBrieQuality = 46;
|
|
34
|
+ String itemName = "agedBrie";
|
62
|
35
|
|
63
|
|
- // One more day
|
64
|
|
- assertTestValues(inventory, 1, 0, 23, -1, 48, 9, 28, 10, 80);
|
|
36
|
+ // When
|
|
37
|
+ agedBrie.setQuality(agedBrie.getQuality() + 1);
|
|
38
|
+ int actualBrieQuality = agedBrie.getQuality();
|
65
|
39
|
|
66
|
|
- // Four more days
|
67
|
|
- assertTestValues(inventory, 4, -4, 15, -5, 50, 5, 36, 10, 80);
|
|
40
|
+ // Then
|
|
41
|
+ Assert.assertEquals(expectedBrieQuality,actualBrieQuality);
|
|
42
|
+ }
|
68
|
43
|
|
69
|
|
- // Three more days
|
70
|
|
- assertTestValues(inventory, 3, -7, 9, -8, 50, 2, 45, 10, 80);
|
|
44
|
+ @Test
|
|
45
|
+ public void testPassQuality() {
|
71
|
46
|
|
72
|
|
- // Five more days
|
73
|
|
- assertTestValues(inventory, 5, -12, 0, -13, 50, -3, 0, 10, 80);
|
74
|
47
|
}
|
75
|
48
|
|
76
|
49
|
}
|
77
|
50
|
|
|
51
|
+// Test for previous code
|
|
52
|
+
|
|
53
|
+//
|
|
54
|
+// public InventoryTest() {
|
|
55
|
+//
|
|
56
|
+// Item wine = new Item("wine", 2, 25);
|
|
57
|
+// Item agedBrie = new Item("Aged Brie", 1, 45);
|
|
58
|
+// Item passes = new Item("Backstage passes to a TAFKAL80ETC concert", 11, 25);
|
|
59
|
+// Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 10, 80 );
|
|
60
|
+//
|
|
61
|
+// Item[] items = {wine, agedBrie, passes, sulfuras};
|
|
62
|
+//
|
|
63
|
+// inventory = new Inventory(items);
|
|
64
|
+// }
|
|
65
|
+//
|
|
66
|
+// public void assertTestValues(Inventory inventory, int days, int wineSellIn, int wineQuality, int brieSellIn, int brieQuality,
|
|
67
|
+// int passSellIn, int passQuality, int sulfurasSellIn, int sulfurasQuality) {
|
|
68
|
+// for (int i = 0; i < days; i++) {
|
|
69
|
+// inventory.updateQuality();
|
|
70
|
+// }
|
|
71
|
+// Item[] items = inventory.getItems();
|
|
72
|
+// Item currentItem = items[0];
|
|
73
|
+// Assert.assertSame("wine", currentItem.getName());
|
|
74
|
+// Assert.assertEquals(wineSellIn, currentItem.getSellIn());
|
|
75
|
+// Assert.assertEquals(wineQuality, currentItem.getQuality());
|
|
76
|
+//
|
|
77
|
+// currentItem = items[1];
|
|
78
|
+// Assert.assertSame("Aged Brie", currentItem.getName());
|
|
79
|
+// Assert.assertEquals(brieSellIn, currentItem.getSellIn());
|
|
80
|
+// Assert.assertEquals(brieQuality, currentItem.getQuality());
|
|
81
|
+//
|
|
82
|
+// currentItem = items[2];
|
|
83
|
+// Assert.assertSame("Backstage passes to a TAFKAL80ETC concert", currentItem.getName());
|
|
84
|
+// Assert.assertEquals(passSellIn, currentItem.getSellIn());
|
|
85
|
+// Assert.assertEquals(passQuality, currentItem.getQuality());
|
|
86
|
+//
|
|
87
|
+// currentItem = items[3];
|
|
88
|
+// Assert.assertSame("Sulfuras, Hand of Ragnaros", currentItem.getName());
|
|
89
|
+// Assert.assertEquals(sulfurasSellIn, currentItem.getSellIn());
|
|
90
|
+// Assert.assertEquals(sulfurasQuality, currentItem.getQuality());
|
|
91
|
+// }
|
|
92
|
+//
|
|
93
|
+// @Test
|
|
94
|
+// public void updateQualityTest(){
|
|
95
|
+// // Given
|
|
96
|
+//
|
|
97
|
+// // One day
|
|
98
|
+// assertTestValues(inventory, 1, 1, 24, 0, 46, 10, 26, 10, 80);
|
|
99
|
+//
|
|
100
|
+// // One more day
|
|
101
|
+// assertTestValues(inventory, 1, 0, 23, -1, 48, 9, 28, 10, 80);
|
|
102
|
+//
|
|
103
|
+// // Four more days
|
|
104
|
+// assertTestValues(inventory, 4, -4, 15, -5, 50, 5, 36, 10, 80);
|
|
105
|
+//
|
|
106
|
+// // Three more days
|
|
107
|
+// assertTestValues(inventory, 3, -7, 9, -8, 50, 2, 45, 10, 80);
|
|
108
|
+//
|
|
109
|
+// // Five more days
|
|
110
|
+// assertTestValues(inventory, 5, -12, 0, -13, 50, -3, 0, 10, 80);
|
|
111
|
+// }
|