-
Notifications
You must be signed in to change notification settings - Fork 0
/
GildedRoseTest.cs
351 lines (279 loc) · 12 KB
/
GildedRoseTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace csharp
{
[TestFixture]
public class GildedRoseTest
{
/// <summary>
/// Aged Brie : Quality increase whith time.
/// Quality can't be greater than 50
/// </summary>
[Test]
public void AgedQualityIncreaseWithTime()
{
int maxValue = 50;
//Arrange
IList<Item> Items = new List<Item> { new Item { Name = "Aged Brie", SellIn = 5, Quality = 5 } };
GildedRose _sut = new GildedRose(Items);
//Act
int originalValueQuality = Items[0].Quality;
while (Items[0].Quality < maxValue)
{
_sut.UpdateQuality();
}
// if we repeat the operation, the quality couldn't be greater than 50
_sut.UpdateQuality();
_sut.UpdateQuality();
//Assert
// Quantity must be greater than the original one and it can't be greater than 50
Assert.IsTrue(Items[0].Name == "Aged Brie");
Assert.Greater(Items[0].Quality, originalValueQuality); // Quantity must be greater than the original one
Assert.AreEqual(Items[0].Quality, maxValue); // after 50 days the quantity must be equal to 50
}
/// <summary>
/// Backstage Pass: Quality increases with time.
/// Quality increases by 2 when there are 10 days or less
/// Quality increases by 3 when there are 5 days or less
/// </summary>
[Test]
public void BackstagePasseQualityincreases()
{
int initQuality = 20;
int step10days = initQuality + 2;
int step5days = initQuality + 3;
//Arrange
IList<Item> Items = new List<Item> {
new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 9, Quality = initQuality },
new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 4, Quality = initQuality } };
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.IsTrue(Items[0].Name == "Backstage passes to a TAFKAL80ETC concert");
Assert.AreEqual(Items[0].Quality, step10days); // Quality increases by 2 when there are 10 days or less
Assert.AreEqual(Items[1].Quality, step5days); // Quality increases by 3 when there are 5 days or less
}
/// <summary>
/// Backstage Pass: Quality increases with time.
/// After concert quality = 0, concert means that the date is exceeded SellIn less than 0
/// </summary>
[Test]
public void BackstagePasseConcert()
{
int initQuality = 20;
//Arrange
IList<Item> Items = new List<Item> {
new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = -1, Quality = initQuality }};
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.IsTrue(Items[0].Name == "Backstage passes to a TAFKAL80ETC concert");
Assert.AreEqual(Items[0].Quality, 0); // After concert quality = 0, concert means that the date is exceeded SellIn less than 0
}
/// <summary>
/// Backstage Pass: Quality increases with time.
/// Quality can't be greater than 50
/// Quality increases by 2 when there are 10 days or less
/// Quality increases by 3 when there are 5 days or less
/// After concert quality = 0, concert means that the date is exceeded SellIn less than 0
/// </summary>
[Test]
public void BackstagePasseIncreaseWithTime()
{
//Arrange
IList<Item> Items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 50, Quality = 5 } };
GildedRose _sut = new GildedRose(Items);
//Act
while (Items[0].Quality != 0)
{
_sut.UpdateQuality();
}
//Assert
// Quality must be 0 and SellIn must be negative
Assert.IsTrue(Items[0].Name == "Backstage passes to a TAFKAL80ETC concert");
Assert.IsTrue(Items[0].SellIn < 0); // SellIn must be negative
Assert.IsTrue(Items[0].Quality == 0); // Quantity must be 0
}
/// <summary>
/// Sulfuras: no expiry date and never loses in quality
/// quality = 80 because legendary object
/// </summary>
[Test]
public static void SulfrasNotChangeWithTime()
{
//Arrange
IList<Item> Items = new List<Item> { new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80 } };
GildedRose _sut = new GildedRose(Items);
var oldQuality = Items[0].Quality;
var oldSellIn = Items[0].SellIn;
//Act
for (int i = 0; i < 50; i++)
{
_sut.UpdateQuality();
}
//Assert
// Sulfuras is a legendary element so nothing must change
Assert.IsTrue(Items[0].Name == "Sulfuras, Hand of Ragnaros");
Assert.AreEqual(Items[0].SellIn, oldSellIn); // SellIn must not change
Assert.AreEqual(Items[0].Quality, oldQuality); // Quality must not change
}
/// <summary>
/// Element: Quality greater or egal 0 and quality less than 50
/// </summary>
[Test]
public void ElementDecrease()
{
//Arrange
int initQuality = 50;
IList<Item> Items = new List<Item> {
new Item { Name = "Element 1", SellIn = 30, Quality = initQuality }
};
GildedRose _sut = new GildedRose(Items);
//Act
// 50-day test
for (int i = 0; i < 50; i++)
{
_sut.UpdateQuality();
}
//Assert
Assert.Less(Items[0].Quality, initQuality); // Quality less than 50
Assert.GreaterOrEqual(Items[0].Quality, 0); // Quality greater or egal 0
}
/// <summary>
/// Element: the quality decreases by 1 each passing day
/// </summary>
[Test]
public void ElementDecreaseByOne()
{
//Arrange
int initQuality = 50;
IList<Item> Items = new List<Item> {
new Item { Name = "Element 1", SellIn = 30, Quality = initQuality }
};
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.AreEqual(Items[0].Quality, initQuality - 1); // no element with a positive SellIn
}
/// <summary>
/// Element: when SellIn is less than or equal to 0 quality decreases by 2 each day
/// </summary>
[Test]
public void ElementDecreaseSellInNegatif()
{
//Arrange
int initQuality = 50;
IList<Item> Items = new List<Item> {
new Item { Name = "Element 1", SellIn = -1, Quality = initQuality }
};
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.AreEqual(Items[0].Quality, initQuality - 2); // no element with a positive SellIn
}
/// <summary>
/// Element: Quality greater or egal 0 and quality less than 50
/// the quality decreases by 1 each passing day
/// when SellIn is less than or equal to 0 quality decreases by 2 each day
/// </summary>
[Test]
public void ElementDecreaseWithTime()
{
//Arrange
IList<Item> Items = new List<Item> {
new Item { Name = "Element 1", SellIn = 0, Quality = 0 },
new Item { Name = "Element 2", SellIn = 10, Quality = 20 },
new Item { Name = "Element 3", SellIn = 20, Quality = 30 },
new Item { Name = "Element 4", SellIn = 30, Quality = 40 },
new Item { Name = "Element 5", SellIn = 40, Quality = 50 }
};
GildedRose _sut = new GildedRose(Items);
//Act
// 50-day test
for (int i = 0; i < 50; i++)
{
_sut.UpdateQuality();
}
//Assert
// After 50 days there must be no element with a positive SellIn and quality greater than 0 and less than 0
Assert.IsTrue(!Items.Any(o => o.SellIn > 0)); // no element with a positive SellIn
Assert.IsTrue(Items.Count(o => o.SellIn < 0) == Items.Count); // all the elements on a negative SellIn
Assert.IsTrue(!Items.Any(o => o.Quality > 0)); // none greater than 0
Assert.IsTrue(!Items.Any(o => o.Quality < 0)); // none less than 0
Assert.IsTrue(Items.Count(o => o.Quality == 0) == Items.Count); // all equal to 0
}
/// <summary>
/// Conjured:
/// The quantity decreases 2 times faster than an element so:
/// - the quality decreases by 2 each passing day
/// </summary>
[Test]
public void ConjuredDecreaseByTwo()
{
//Arrange
int initQuality = 50;
IList<Item> Items = new List<Item> {
new Item { Name = "Conjured Mana Cake", SellIn = 20, Quality = initQuality }
};
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.AreEqual(Items[0].Quality, initQuality - 2); // the quality decreases by 2 each passing day
}
/// <summary>
/// Conjured:
/// The quantity decreases 2 times faster than an element so:
/// - When SellIn is less than or equal to 0 0 quality decreases by 4 each day
/// </summary>
[Test]
public void ConjuredDecreaseByFour()
{
//Arrange
int initQuality = 50;
IList<Item> Items = new List<Item> {
new Item { Name = "Conjured Mana Cake", SellIn = -1, Quality = initQuality }
};
GildedRose _sut = new GildedRose(Items);
//Act
_sut.UpdateQuality();
//Assert
Assert.AreEqual(Items[0].Quality, initQuality - 4); // When SellIn is less than or equal to 0 0 quality decreases by 4 each day
}
/// <summary>
/// Conjured: Quality greater than 0 and quality less than 50
/// The quantity decreases 2 times faster than an element so:
/// - the quality decreases by 2 each passing day
/// - When SellIn is less than or equal to 0 0 quality decreases by 4 each day
/// </summary>
[Test]
public void ConjuredDecreaseWithTime()
{
//Arrange
IList<Item> Items = new List<Item> {
new Item { Name = "Conjured Mana Cake", SellIn = 20, Quality = 50 },
new Item { Name = "Element", SellIn = 20, Quality = 50 }
};
GildedRose _sut = new GildedRose(Items);
//Act
// 50 - day test
for (int i = 0; i < 50; i++)
{
_sut.UpdateQuality();
}
//Assert
//After 50 days there must be no element with a positive SellIn and quality greater than 0 and less than 0
Assert.IsTrue(!Items.Any(o => o.SellIn > 0)); // no element with a positive SellIn
Assert.IsTrue(Items.Count(o => o.SellIn < 0) == Items.Count); // all the elements on a negative SellIn
Assert.IsTrue(!Items.Any(o => o.Quality > 0)); // none greater than 0
Assert.IsTrue(!Items.Any(o => o.Quality < 0)); // none less than 0
Assert.IsTrue(Items.Count(o => o.Quality == 0) == Items.Count); // all equal to 0
}
}
}