-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallum_basket_spec.rb
209 lines (201 loc) · 5.6 KB
/
callum_basket_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
=begin require 'callum_basket'
describe Basket do
basket = Basket.new
describe '#add' do
it 'can add a valid item' do
basket = Basket.new(cart_one)
basket.add("FR1")
expect(cart_one["FR1"]).to eq(1)
end
end
end
=end
require 'callum_basket'
describe Basket do
it 'can add an FR1' do
basket = Basket.new()
basket.add("FR1")
expect(basket.cart_one["FR1"]).to eql(1)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can add an SR1' do
basket = Basket.new()
basket.add("SR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(1)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can add an CF1' do
basket = Basket.new()
basket.add("CF1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(1)
end
it 'can add two FR1' do
basket = Basket.new()
basket.add("FR1")
basket.add("FR1")
expect(basket.cart_one["FR1"]).to eql(2)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can add two SR1' do
basket = Basket.new()
basket.add("SR1")
basket.add("SR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(2)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can add two CF1' do
basket = Basket.new()
basket.add("CF1")
basket.add("CF1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(2)
end
it 'can remove one FR1' do
basket = Basket.new
basket.add("FR1")
basket.add("FR1")
basket.remove("FR1")
expect(basket.cart_one["FR1"]).to eql(1)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can remove one SR1' do
basket = Basket.new
basket.add("SR1")
basket.add("SR1")
basket.remove("SR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(1)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can remove one CF1' do
basket = Basket.new
basket.add("CF1")
basket.add("CF1")
basket.remove("CF1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(1)
end
it 'doesnt change when removing one FR1, when FR1 is 0' do
basket = Basket.new
basket.remove("FR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'doesnt change when removing one SR1, when SR1 is 0' do
basket = Basket.new
basket.remove("SR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'doesnt change when removing one CF1, when CF1 is 0' do
basket = Basket.new
basket.remove("CF1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can remove two FR1' do
basket = Basket.new
basket.add("FR1")
basket.add("FR1")
basket.add("FR1")
basket.add("FR1")
basket.remove("FR1")
basket.remove("FR1")
expect(basket.cart_one["FR1"]).to eql(2)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can remove two SR1' do
basket = Basket.new
basket.add("SR1")
basket.add("SR1")
basket.add("SR1")
basket.add("SR1")
basket.remove("SR1")
basket.remove("SR1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(2)
expect(basket.cart_one["CF1"]).to eql(0)
end
it 'can remove two CF1' do
basket = Basket.new
basket.add("CF1")
basket.add("CF1")
basket.add("CF1")
basket.add("CF1")
basket.remove("CF1")
basket.remove("CF1")
expect(basket.cart_one["FR1"]).to eql(0)
expect(basket.cart_one["SR1"]).to eql(0)
expect(basket.cart_one["CF1"]).to eql(2)
end
it 'can calculate total of one FR1' do
basket = Basket.new
basket.add("FR1")
expect(basket.sub_total).to eql(3.11)
end
it 'can calculate total of two FR1' do
basket = Basket.new
basket.add("FR1")
basket.add("FR1")
expect(basket.sub_total).to eql(6.22)
end
it 'can calculate total of one SR1' do
basket = Basket.new
basket.add("SR1")
expect(basket.sub_total).to eql(5.00)
end
it 'can calculate total of two SR1' do
basket = Basket.new
basket.add("SR1")
basket.add("SR1")
expect(basket.sub_total).to eql(10.00)
end
it 'can calculate total of one CF1' do
basket = Basket.new
basket.add("CF1")
expect(basket.sub_total).to eql(11.23)
end
it 'can calculate total total of two CF1' do
basket = Basket.new
basket.add("CF1")
basket.add("CF1")
expect(basket.sub_total).to eql(22.46)
end
it 'can calculate total one of each product' do
basket = Basket.new
basket.add("FR1")
basket.add("SR1")
basket.add("CF1")
expect(basket.sub_total).to eql(19.34)
end
it 'discount tea test' do
basket = Basket.new
basket.add("FR1")
basket.add("FR1")
basket.add("FR1")
basket.add("CF1")
expect(basket.sub_total).to eql(20.56)
expect(basket.fruit_tea_price).to eql(6.22)
end
it 'discount strawberry test' do
basket = Basket.new
basket.add("SR1")
basket.add("SR1")
basket.add("SR1")
expect(basket.strawberries_price).to eql(1.50)
expect(basket.sub_total).to eql(15.00)
end
end