-
Notifications
You must be signed in to change notification settings - Fork 0
/
GildedRoseTest.cs
114 lines (105 loc) · 4.52 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
using NUnit.Framework;
using System.Collections.Generic;
namespace csharp
{
[TestFixture]
public class GildedRoseTest
{
private static void UpdateQualityAndCheckItem(GildedRose app, Item item, int expectedSellIn, int expectedQuality)
{
app.Update();
Assert.AreEqual(expectedSellIn, item.SellIn);
Assert.AreEqual(expectedQuality, item.Quality);
}
[Test]
public void TestFrameworkWorksProperly()
{
IList<Item> Items = new List<Item> { Item.NormalItem("foo", 0, 0) };
GildedRose app = new GildedRose(Items);
app.Update();
Assert.AreEqual("foo", Items[0].Name);
}
/**
* - All items have a SellIn value which denotes the number of days we have to sell the item
* - All items have a Quality value which denotes how valuable the item is
* - At the end of each day our system lowers both values for every item
*/
[Test]
public void NormalItemSellInAndQualityDecreaseByOne()
{
IList<Item> Items = new List<Item> { Item.NormalItem("Normal Item", 25, 15) };
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 24, 14);
UpdateQualityAndCheckItem(app, Items[0], 23, 13);
}
/**
* - Once the sell by date has passed, Quality degrades twice as fast
*/
[Test]
public void NormalItemQualityDegradesTwiceAsFast()
{
IList<Item> Items = new List<Item> { Item.NormalItem("Normal Item", 1, 15)};
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 0, 14);
UpdateQualityAndCheckItem(app, Items[0], -1, 12);
UpdateQualityAndCheckItem(app, Items[0], -2, 10);
}
/**
* - "Aged Brie" actually increases in Quality the older it gets
*/
[Test]
public void AgedBrieIncreasesInQuality()
{
IList<Item> Items = new List<Item> { Item.AgedBrie("Aged Brie", 25, 15)};
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 24, 16);
UpdateQualityAndCheckItem(app, Items[0], 23, 17);
}
/**
* - The Quality of an item is never more than 50
*/
[Test]
public void QualityNeverMoreThan50()
{
IList<Item> Items = new List<Item> { Item.AgedBrie("Aged Brie", 25, 50) };
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 24, 50);
Items = new List<Item> { Item.AgedBrie("Aged Brie", -1, 48) };
app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], -2, 50);
}
/**
* - "Sulfuras", being a legendary item, never has to be sold or decreases in Quality
*/
[Test]
public void SulfurasIsSpecial()
{
IList<Item> Items = new List<Item> { new Sulfuras { Name = "Sulfuras, Hand of Ragnaros", SellIn = 25, Quality = 15 } };
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 25, 15);
}
/**
* - "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
* Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but
* Quality drops to 0 after the concert
*/
[Test]
public void BacstagePassesAreSpecial()
{
IList<Item> Items = new List<Item> { new BackstagePasses { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 11, Quality = 15 } };
GildedRose app = new GildedRose(Items);
UpdateQualityAndCheckItem(app, Items[0], 10, 16);
UpdateQualityAndCheckItem(app, Items[0], 9, 18);
UpdateQualityAndCheckItem(app, Items[0], 8, 20);
UpdateQualityAndCheckItem(app, Items[0], 7, 22);
UpdateQualityAndCheckItem(app, Items[0], 6, 24);
UpdateQualityAndCheckItem(app, Items[0], 5, 26);
UpdateQualityAndCheckItem(app, Items[0], 4, 29);
UpdateQualityAndCheckItem(app, Items[0], 3, 32);
UpdateQualityAndCheckItem(app, Items[0], 2, 35);
UpdateQualityAndCheckItem(app, Items[0], 1, 38);
UpdateQualityAndCheckItem(app, Items[0], 0, 41);
UpdateQualityAndCheckItem(app, Items[0], -1, 0);
}
}
}