-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_coffeespecs.py
339 lines (283 loc) · 10.9 KB
/
test_coffeespecs.py
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
import unittest
from coffeespecs import Coffee, get_all_word_tokens
class TestCoffeeValidation(unittest.TestCase):
def test_minimal_spec(self):
c = Coffee('')
self.assertFalse(c.validate())
self.assertTrue(c.add_spec('type', 'C'))
self.assertTrue(c.validate())
self.assertTrue(c.add_spec('size', 'l'))
self.assertTrue(c.validate())
# Still valid if we add more.
self.assertTrue(c.add_spec('milk', 'soy'))
class TestParser(unittest.TestCase):
def test_get_tokens(self):
tokens = get_all_word_tokens()
self.assertIn('chocolate', tokens)
self.assertIn('extra-shot', tokens)
# All tokens should be lowercase
self.assertTrue(all([x.islower() for x in tokens]))
def test_parse(self):
c = Coffee('Large Cap')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Large',
})
def test_parse_abbreviation1(self):
c = Coffee('LC')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Large',
})
def test_parse_abbreviation2(self):
c = Coffee('SC')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Small',
})
def test_parse_bigram_sugars(self):
c = Coffee('Large Cap 2 Sugars')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Large',
'sugar': '2 Sugars',
})
def test_parse_words1(self):
c = Coffee('Small strong cap')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Small',
'strength': 'Extra-shot',
})
def test_parse_words2(self):
c = Coffee('Small doubleshot cap')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Small',
'strength': 'Extra-shot',
})
def test_parse_words(self):
c = Coffee('Small Latte')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Latte',
'size': 'Small',
})
def test_parse_abbreviation_sl(self):
c = Coffee('SL')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Latte',
'size': 'Small',
})
def test_parse_abbreviation_ll(self):
c = Coffee('LL')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Latte',
'size': 'Large',
})
def test_parse_abbreviation_cl(self):
c = Coffee('CL')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Large',
})
def test_parse_abbreviation_2s(self):
c = Coffee('CL 2S')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'size': 'Large',
'sugar': '2 Sugars',
})
def test_parse_words_iced(self):
c = Coffee('Large Iced Latte')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Latte',
'size': 'Large',
'iced': 'Iced',
})
def test_parse_words3(self):
c = Coffee('Large Flat white')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Flat White',
'size': 'Large',
})
def test_parse_words_and_abbreviations_and_bigrams(self):
c = Coffee('Large FW 3 Sugars')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Flat White',
'size': 'Large',
'sugar': '3 Sugars',
})
def test_parse_words4(self):
c = Coffee('Regular Flat White')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Flat White',
'size': 'Regular',
})
def test_parse_words_many(self):
c = Coffee('Soy decaf latte with 2 sugars')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Latte',
'sugar': '2 Sugars',
'decaf': 'Decaf',
'milk': 'Soy',
})
def test_parse_abbreviation3(self):
c = Coffee('lffw')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Flat White',
'milk': 'Lactose Free',
})
def test_parse_words_iced_coffee(self):
c = Coffee('Soy Iced Coffee')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Iced Coffee',
'milk': 'Soy',
})
def test_parse_words_iced_coffee2(self):
c = Coffee('Skim Iced Chocolate')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Iced Chocolate',
'milk': 'Skim',
})
def test_parse_words_lactose_free(self):
c = Coffee('Lactose Free Cap')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Cappuccino',
'milk': 'Lactose Free',
})
def test_parse_abbreviation4(self):
c = Coffee('lfw')
self.assertTrue(c.validate())
self.assertEqual(c.specs, {
'type': 'Flat White',
'size': 'Large',
})
def test_abbreviation_parsing(self):
self.assertEqual(str(Coffee('yfw')), 'Regular Soy Flat White')
self.assertEqual(str(Coffee('lyc')), 'Large Soy Cappuccino')
self.assertEqual(str(Coffee('yhc')), 'Regular Soy Hot Chocolate')
self.assertEqual(str(Coffee('syc')), 'Small Soy Cappuccino')
self.assertEqual(str(Coffee('syfw')), 'Small Soy Flat White')
self.assertEqual(str(Coffee('skl')), 'Regular Skim Latte')
self.assertEqual(str(Coffee('xskl')), 'Regular Skim Extra-shot Latte')
self.assertEqual(str(Coffee('sk fw')), 'Regular Skim Flat White')
self.assertEqual(str(Coffee('stl')), 'Regular Extra-shot Latte')
self.assertEqual(str(Coffee('shc')), 'Small Hot Chocolate')
self.assertEqual(str(Coffee('lhc')), 'Large Hot Chocolate')
def test_punctuation(self):
self.assertEqual(str(Coffee('LC!')), 'Large Cappuccino')
self.assertEqual(str(Coffee('Double-shot, soy, latte!')), 'Regular Soy Extra-shot Latte')
self.assertEqual(str(Coffee('Double-shot, soy, latte!')), 'Regular Soy Extra-shot Latte')
def test_iced_choc_vs_iced_hot_choc(self):
self.assertEqual(str(Coffee('icy choc')), 'Regular Iced Chocolate')
self.assertEqual(str(Coffee('chocolate iced')), 'Regular Iced Hot Chocolate')
self.assertEqual(str(Coffee('icy cold chocolate')), 'Regular Iced Hot Chocolate')
self.assertEqual(str(Coffee('iced chocco')), 'Regular Iced Chocolate')
self.assertEqual(str(Coffee('hot chocco')), 'Regular Hot Chocolate')
class TestWeirdCoffeeInput(unittest.TestCase):
def test_joel(self):
c = Coffee('It is a truth universally acknowledged, that a single joel in possession of a good fortune, must be in want of an extra-shot piccolo latte in the morning, plox.')
self.assertEqual(c.specs, {
'type': 'Piccolo Latte',
'strength': 'Extra-shot',
})
self.assertTrue(c.validate())
def test_liam(self):
c = Coffee('let\'s try this again. I would very much enjoy if you could provide me with an Iced latte please thank you for listening to my TED Talk')
self.assertEqual(c.specs, {
'type': 'Latte',
'iced': 'Iced',
})
self.assertTrue(c.validate())
def test_shelley(self):
c = Coffee('gimme the flat white bean pls')
self.assertEqual(c.specs, {
'type': 'Flat White',
})
self.assertTrue(c.validate())
def test_shelley2(self):
c = Coffee('yo beanie boy give me a smol iced latte pls')
self.assertEqual(c.specs, {
'size': 'Small',
'iced': 'Iced',
'type': 'Latte',
})
self.assertTrue(c.validate())
def test_shelley3(self):
c = Coffee('my best boy hit me with an iced latte pls')
self.assertEqual(c.specs, {
'iced': 'Iced',
'type': 'Latte'
})
def test_jackson(self):
c = Coffee('bestow upon me thy chocolated fount in the morrow, i\'m ploxed to request this of you')
self.assertFalse(c.validate())
def test_ben(self):
c = Coffee('hit me up with a delicious cold brew, please destroy me with the bean')
self.assertEqual(c.specs, {
'type': 'Cold Drip'
})
def test_jack(self):
c = Coffee('Gimmie one of them icy chocco bois please')
self.assertEqual(c.specs, {
'type': 'Iced Chocolate',
})
class TestPrettyPrint(unittest.TestCase):
def test_print_large_cap(self):
c = Coffee('Large Cap')
self.assertEqual('Large Cappuccino', str(c))
def test_print_small_cap(self):
c = Coffee('SC')
self.assertEqual('Small Cappuccino', str(c))
def test_print_large_cap2(self):
c = Coffee('Large Cap 2 Sugars')
self.assertEqual('Large Cappuccino with 2 Sugars', str(c))
def test_print_small_strong_cap(self):
c = Coffee('Small strong cap')
self.assertEqual('Small Extra-shot Cappuccino', str(c))
def test_print_small_latte(self):
c = Coffee('Small Latte')
self.assertEqual('Small Latte', str(c))
def test_print_reg_latte(self):
c = Coffee('Reg L')
self.assertEqual('Regular Latte', str(c))
def test_print_large_latte(self):
c = Coffee('LL')
self.assertEqual('Large Latte', str(c))
def test_print_large_iced_latte(self):
c = Coffee('Large Iced Latte')
self.assertEqual('Large Iced Latte', str(c))
def test_print_large_flat_white(self):
c = Coffee('Large Flat white')
self.assertEqual('Large Flat White', str(c))
def test_print_large_flat_white_3s(self):
c = Coffee('Large FW 3 Sugars')
self.assertEqual('Large Flat White with 3 Sugars', str(c))
def test_print_regular_flat_white(self):
c = Coffee('Regular Flat White')
self.assertEqual('Regular Flat White', str(c))
def test_print_soy_decaf_latte_2s(self):
c = Coffee('Soy decaf latte with 2 sugars')
self.assertEqual('Regular Soy Decaf Latte with 2 Sugars', str(c))
if __name__ == '__main__':
unittest.main()