forked from kajabi-mike/gilded-rose-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgilded-rose.test.js
More file actions
191 lines (158 loc) · 7 KB
/
gilded-rose.test.js
File metadata and controls
191 lines (158 loc) · 7 KB
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
const tick = require("./");
expect.extend({
toMatchSellInAndQuality(received, sellIn, quality) {
const receivedValues = `[sellIn: ${received.sellIn}, quality: ${received.quality}]`;
const expectedValues = `[sellIn: ${sellIn}, quality: ${quality}]`;
const valuesComparison = `\n Received ${receivedValues}\n Expected ${expectedValues}`;
if (received.sellIn === sellIn && received.quality === quality) {
return {
pass: true,
message: () => `expected values not to match:${valuesComparison}`
}
}
return {
pass: false,
message: () => `expected values to match:${valuesComparison}`
}
},
});
describe("Gilded Rose", () => {
describe("Normal Item", () => {
test("before sell date", () => {
const item = { name: "Normal Item", sellIn: 5, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(4, 9);
});
test("on sell date", () => {
const item = { name: "Normal Item", sellIn: 0, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-1, 8);
});
test("after sell date", () => {
const item = { name: "Normal Item", sellIn: -10, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-11, 8);
});
test("of zero quality", () => {
const item = { name: "Normal Item", sellIn: 5, quality: 0 };
expect(tick(item)).toMatchSellInAndQuality(4, 0);
});
});
describe("Aged Brie", () => {
test("before sell date", () => {
const item = { name: "Aged Brie", sellIn: 5, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(4, 11);
});
test("with max quality", () => {
const item = { name: "Aged Brie", sellIn: 5, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(4, 50);
});
test("on sell date", () => {
const item = { name: "Aged Brie", sellIn: 0, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-1, 12);
});
test("on sell date near max quality", () => {
const item = { name: "Aged Brie", sellIn: 0, quality: 49 };
expect(tick(item)).toMatchSellInAndQuality(-1, 50);
});
test("on sell date with max quality", () => {
const item = { name: "Aged Brie", sellIn: 0, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(-1, 50);
});
test("after sell date", () => {
const item = { name: "Aged Brie", sellIn: -10, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-11, 12);
});
test("after sell date with max quality", () => {
const item = { name: "Aged Brie", sellIn: -10, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(-11, 50);
});
});
describe("Legendary Item (Sulfuras, Hand of Ragnaros)", () => {
test("before sell date", () => {
const item = { name: "Sulfuras, Hand of Ragnaros", sellIn: 5, quality: 80 };
expect(tick(item)).toMatchSellInAndQuality(5, 80);
});
test("on sell date", () => {
const item = { name: "Sulfuras, Hand of Ragnaros", sellIn: 0, quality: 80 };
expect(tick(item)).toMatchSellInAndQuality(0, 80);
});
test("after sell date", () => {
const item = { name: "Sulfuras, Hand of Ragnaros", sellIn: -10, quality: 80 };
expect(tick(item)).toMatchSellInAndQuality(-10, 80);
});
});
describe("Backstage Pass", () => {
test("long before sell date", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 11, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(10, 11);
});
test("long before sell date at max quality", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 11, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(10, 50);
});
test("medium close to sell date upper bound", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(9, 12);
});
test("medium close to sell date upper bound at max quality", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 10, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(9, 50);
});
test("medium close to sell date lower bound", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 6, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(5, 12);
});
test("medium close to sell date lower bound at max quality", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 6, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(5, 50);
});
test("very close to sell date upper bound", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(4, 13);
});
test("very close to sell date upper bound at max quality", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 5, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(4, 50);
});
test("very close to sell date lower bound", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 1, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(0, 13);
});
test("very close to sell date lower bound at max quality", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 1, quality: 50 };
expect(tick(item)).toMatchSellInAndQuality(0, 50);
});
test("on sell date", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: 0, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-1, 0);
});
test("after sell date", () => {
const item = { name: "Backstage passes to a TAFKAL80ETC concert", sellIn: -10, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-11, 0);
});
});
describe.skip("Conjured Item", () => {
test("before sell date", () => {
const item = { name: "Conjured Mana Cake", sellIn: 5, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(4, 8);
});
test("before sell date at zero quality", () => {
const item = { name: "Conjured Mana Cake", sellIn: 5, quality: 0 };
expect(tick(item)).toMatchSellInAndQuality(4, 0);
});
test("on sell date", () => {
const item = { name: "Conjured Mana Cake", sellIn: 0, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-1, 6);
});
test("on sell date at zero quality", () => {
const item = { name: "Conjured Mana Cake", sellIn: 0, quality: 0 };
expect(tick(item)).toMatchSellInAndQuality(-1, 0);
});
test("after sell date", () => {
const item = { name: "Conjured Mana Cake", sellIn: -10, quality: 10 };
expect(tick(item)).toMatchSellInAndQuality(-11, 6);
});
test("after sell date at zero quality", () => {
const item = { name: "Conjured Mana Cake", sellIn: -10, quality: 0 };
expect(tick(item)).toMatchSellInAndQuality(-11, 0);
});
});
});