forked from mdx-dev/platform-code-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_quality_spec.rb
237 lines (189 loc) · 7.02 KB
/
update_quality_spec.rb
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
require 'rspec'
require 'update_quality'
describe '#update_quality' do
context 'Given a single award' do
let(:initial_expires_in) { 5 }
let(:initial_quality) { 10 }
let(:award) { Award.new(name, initial_expires_in, initial_quality) }
context 'when quality is updated' do
before do
update_quality([award])
end
context 'given a normal award' do
let(:name) { 'NORMAL ITEM' }
before do
# Verify that this is always true in the current context
expect(award.expires_in).to eq(initial_expires_in-1)
end
context 'before expiration date' do
specify { expect(award.quality).to eq(initial_quality-1) }
end
context 'on expiration date' do
let(:initial_expires_in) { 0 }
specify { expect(award.quality).to eq(initial_quality-2) }
end
context 'after expiration date' do
let(:initial_expires_in) { -10 }
specify { expect(award.quality).to eq(initial_quality-2) }
end
context 'of zero quality' do
let(:initial_quality) { 0 }
specify { expect(award.quality).to eq(0) }
end
end
context 'given Blue First' do
let(:name) { 'Blue First' }
before do
# Verify that this is always true in the current context
award.expires_in.should == initial_expires_in-1
end
context 'before expiration date' do
specify { expect(award.quality).to eq(initial_quality+1) }
context 'with max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'on expiration date' do
let(:initial_expires_in) { 0 }
specify { expect(award.quality).to eq(initial_quality+2) }
context 'near max quality' do
let(:initial_quality) { 49 }
specify { expect(award.quality).to eq(50) }
end
context 'with max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'after expiration date' do
let(:initial_expires_in) { -10 }
specify { expect(award.quality).to eq(initial_quality+2) }
context 'with max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
end
context 'given Blue Distinction Plus' do
let(:initial_quality) { 80 }
let(:name) { 'Blue Distinction Plus' }
before do
# Verify that this is always true in the current context
award.expires_in.should == initial_expires_in
end
context 'before expiration date' do
specify { expect(award.quality).to eq(initial_quality) }
end
context 'on expiration date' do
let(:initial_expires_in) { 0 }
specify { expect(award.quality).to eq(initial_quality) }
end
context 'after expiration date' do
let(:initial_expires_in) { -10 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'given Blue Compare' do
let(:name) { 'Blue Compare' }
before do
# Verify that this is always true in the current context
award.expires_in.should == initial_expires_in-1
end
context 'long before expiration date' do
let(:initial_expires_in) { 11 }
specify { expect(award.quality).to eq(initial_quality+1) }
context 'at max quality' do
let(:initial_quality) { 50 }
end
end
context 'medium close to expiration date (upper bound)' do
let(:initial_expires_in) { 10 }
specify { expect(award.quality).to eq(initial_quality+2) }
context 'at max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'medium close to expiration date (lower bound)' do
let(:initial_expires_in) { 6 }
specify { expect(award.quality).to eq(initial_quality+2) }
context 'at max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'very close to expiration date (upper bound)' do
let(:initial_expires_in) { 5 }
specify { expect(award.quality).to eq(initial_quality+3) }
context 'at max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'very close to expiration date (lower bound)' do
let(:initial_expires_in) { 1 }
specify { expect(award.quality).to eq(initial_quality+3) }
context 'at max quality' do
let(:initial_quality) { 50 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'on expiration date' do
let(:initial_expires_in) { 0 }
specify { expect(award.quality).to eq(0) }
end
context 'after expiration date' do
let(:initial_expires_in) { -10 }
specify { expect(award.quality).to eq(0) }
end
end
context 'given a Blue Star award' do
before { pending }
let(:name) { 'Blue Star' }
before { award.expires_in.should == initial_expires_in-1 }
context 'before the expiration date' do
let(:initial_expires_in) { 5 }
specify { expect(award.quality).to eq(initial_quality-2) }
context 'at zero quality' do
let(:initial_quality) { 0 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'on expiration date' do
let(:initial_expires_in) { 0 }
specify { expect(award.quality).to eq(initial_quality-4) }
context 'at zero quality' do
let(:initial_quality) { 0 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
context 'after expiration date' do
let(:initial_expires_in) { -10 }
specify { expect(award.quality).to eq(initial_quality-4) }
context 'at zero quality' do
let(:initial_quality) { 0 }
specify { expect(award.quality).to eq(initial_quality) }
end
end
end
end
end
context 'Given several award' do
let(:awards) {
[
Award.new('NORMAL ITEM', 5, 10),
Award.new('Blue First', 3, 10),
]
}
context 'when quality is updated' do
before do
update_quality(awards)
end
specify { expect(awards[0].quality).to eq(9) }
specify { expect(awards[0].expires_in).to eq(4) }
specify { expect(awards[1].quality).to eq(11) }
specify { expect(awards[1].expires_in).to eq(2) }
end
end
end