|
@@ -4,9 +4,143 @@ import org.junit.Assert;
|
4
|
4
|
import org.junit.Test;
|
5
|
5
|
|
6
|
6
|
public class InventoryTest {
|
|
7
|
+
|
|
8
|
+ Item genericItem = new Item("Generic Item",7,25);
|
|
9
|
+ Item agedBrie = new Item("Aged Brie",7,10);
|
|
10
|
+ Item sulfuras = new Item("Sulfuras, Hand of Ragnaros", 7, 10);
|
|
11
|
+ Item backstagePasses = new Item("Backstage passes to a TAFKAL80ETC concert", 14, 10);
|
|
12
|
+ Item[] items = {genericItem, agedBrie, sulfuras, backstagePasses};
|
|
13
|
+
|
|
14
|
+ @Test
|
|
15
|
+ public void updateQuality0() {
|
|
16
|
+ Inventory inventory = new Inventory(items);
|
|
17
|
+
|
|
18
|
+ // test that quality goes down each day
|
|
19
|
+ int before = items[0].getQuality();
|
|
20
|
+ inventory.updateQuality();
|
|
21
|
+ int after = items[0].getQuality();
|
|
22
|
+
|
|
23
|
+ System.out.println(before);
|
|
24
|
+ System.out.println(after);
|
|
25
|
+
|
|
26
|
+ Assert.assertTrue(before > after);
|
|
27
|
+ }
|
|
28
|
+
|
7
|
29
|
@Test
|
8
|
|
- public void updateQuantityTest(){
|
9
|
|
- Assert.assertEquals(1, 1);
|
|
30
|
+ public void updateQuality1() {
|
|
31
|
+ Inventory inventory = new Inventory(items);
|
|
32
|
+
|
|
33
|
+ // test that quality is never < 0
|
|
34
|
+ // make 100 "days" pass
|
|
35
|
+ for (int i = 0; i < 100; i++) {
|
|
36
|
+ inventory.updateQuality();
|
|
37
|
+ }
|
|
38
|
+ int after = items[0].getQuality();
|
|
39
|
+
|
|
40
|
+ System.out.println(after);
|
|
41
|
+
|
|
42
|
+ Assert.assertTrue(after >= 0);
|
10
|
43
|
}
|
|
44
|
+
|
|
45
|
+ @Test
|
|
46
|
+ public void updateQuality2() {
|
|
47
|
+ Inventory inventory = new Inventory(items);
|
|
48
|
+
|
|
49
|
+ // aged brie test
|
|
50
|
+ int before = items[1].getQuality();
|
|
51
|
+ inventory.updateQuality();
|
|
52
|
+ int after = items[1].getQuality();
|
|
53
|
+
|
|
54
|
+ System.out.println(before);
|
|
55
|
+ System.out.println(after);
|
|
56
|
+
|
|
57
|
+ Assert.assertTrue(before < after);
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ @Test
|
|
61
|
+ public void updateQuality3() {
|
|
62
|
+ Inventory inventory = new Inventory(items);
|
|
63
|
+
|
|
64
|
+ // test that quality degrades 2x fast after sellIn expires
|
|
65
|
+ for (int i = 0; i < 8; i++) {
|
|
66
|
+ inventory.updateQuality();
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ int expectedValue = 25 - 7 - 2;
|
|
70
|
+ int actualValue = items[0].getQuality();
|
|
71
|
+
|
|
72
|
+ Assert.assertTrue(expectedValue == actualValue);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void updateQuality4() {
|
|
77
|
+ Inventory inventory = new Inventory(items);
|
|
78
|
+
|
|
79
|
+ // test that quality never higher than 50 (w/ aged brie)
|
|
80
|
+ for (int i = 0; i < 100; i++) {
|
|
81
|
+ inventory.updateQuality();
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ //get aged brie quality
|
|
85
|
+ int after = items[1].getQuality();
|
|
86
|
+
|
|
87
|
+ Assert.assertTrue(after <= 50);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ @Test
|
|
91
|
+ public void updateQuality5() {
|
|
92
|
+ Inventory inventory = new Inventory(items);
|
|
93
|
+
|
|
94
|
+ int before = items[2].getQuality();
|
|
95
|
+
|
|
96
|
+ // test that Sulfuras quality never degrades
|
|
97
|
+ for (int i = 0; i < 100; i++) {
|
|
98
|
+ inventory.updateQuality();
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ // call for Sulfuras quality
|
|
102
|
+ int after = items[2].getQuality();
|
|
103
|
+
|
|
104
|
+ Assert.assertTrue(before == after);
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+ @Test
|
|
108
|
+ public void updateQuality6() {
|
|
109
|
+ Inventory inventory = new Inventory(items);
|
|
110
|
+
|
|
111
|
+ // backstage passes test 1
|
|
112
|
+ for (int i = 0; i < 5; i++) {
|
|
113
|
+ inventory.updateQuality();
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ int expectedValue = 10 + 1*4 + 2;
|
|
117
|
+ int actualValue = items[3].getQuality();
|
|
118
|
+
|
|
119
|
+ Assert.assertTrue(actualValue == expectedValue);
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ @Test
|
|
123
|
+ public void updateQuality7() {
|
|
124
|
+ Inventory inventory = new Inventory(items);
|
|
125
|
+
|
|
126
|
+ // backstage passes test 2
|
|
127
|
+ for (int i = 0; i < 10; i++) {
|
|
128
|
+ inventory.updateQuality();
|
|
129
|
+ }
|
|
130
|
+
|
|
131
|
+ int expectedValue = 10 + 1*4 + 2*5 + 3;
|
|
132
|
+ int actualValue = items[3].getQuality();
|
|
133
|
+
|
|
134
|
+ Assert.assertTrue(actualValue == expectedValue);
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ @Test
|
|
138
|
+ public void setNameTest() {
|
|
139
|
+ Item testItem = new Item("Generic Item",7,25);
|
|
140
|
+ testItem.setName("Health Potion");
|
|
141
|
+
|
|
142
|
+ Assert.assertTrue(testItem.getName().equals("Health Potion"));
|
|
143
|
+ }
|
|
144
|
+
|
11
|
145
|
}
|
12
|
146
|
|