Skip to content

Commit 55a8fd2

Browse files
committed
Reformatted test file to test file plus test data file.
1 parent 82e77ce commit 55a8fd2

File tree

3 files changed

+503
-149
lines changed

3 files changed

+503
-149
lines changed

exercises/concept/mecha-munch-management/dict_methods.py

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
# """Functions to manage a users shopping cart items."""
2+
#
3+
#
4+
# def add_item(current_cart, items_to_add):
5+
# """Add items to shopping cart.
6+
#
7+
# :param current_cart: dict - the current shopping cart.
8+
# :param items_to_add: iterable - items to add to the cart.
9+
# :return: dict - the updated user cart dictionary.
10+
# """
11+
#
12+
# pass
13+
#
14+
#
15+
# def read_notes(notes):
16+
# """Create user cart from an iterable notes entry.
17+
#
18+
# :param notes: iterable of items to add to cart.
19+
# :return: dict - a user shopping cart dictionary.
20+
# """
21+
#
22+
# pass
23+
#
24+
#
25+
# def update_recipes(ideas, recipe_updates):
26+
# """Update the recipe ideas dictionary.
27+
#
28+
# :param ideas: dict - The "recipe ideas" dict.
29+
# :param recipe_updates: dict - dictionary with updates for the ideas section.
30+
# :return: dict - updated "recipe ideas" dict.
31+
# """
32+
#
33+
# pass
34+
#
35+
#
36+
# def sort_entries(cart):
37+
# """Sort a users shopping cart in alphabetically order.
38+
#
39+
# :param cart: dict - a users shopping cart dictionary.
40+
# :return: dict - users shopping cart sorted in alphabetical order.
41+
# """
42+
#
43+
# pass
44+
#
45+
#
46+
# def send_to_store(cart, aisle_mapping):
47+
# """Combine users order to aisle and refrigeration information.
48+
#
49+
# :param cart: dict - users shopping cart dictionary.
50+
# :param aisle_mapping: dict - aisle and refrigeration information dictionary.
51+
# :return: dict - fulfillment dictionary ready to send to store.
52+
# """
53+
#
54+
# pass
55+
#
56+
#
57+
# def update_store_inventory(fulfillment_cart, store_inventory):
58+
# """Update store inventory levels with user order.
59+
#
60+
# :param fulfillment cart: dict - fulfillment cart to send to store.
61+
# :param store_inventory: dict - store available inventory
62+
# :return: dict - store_inventory updated.
63+
# """
64+
#
65+
# pass
66+
"""Functions to manage a users shopping cart items."""
67+
168
"""Functions to manage a users shopping cart items."""
269

370

@@ -9,7 +76,11 @@ def add_item(current_cart, items_to_add):
976
:return: dict - the updated user cart dictionary.
1077
"""
1178

12-
pass
79+
for item in items_to_add:
80+
current_cart.setdefault(item, 0)
81+
current_cart[item] += 1
82+
83+
return current_cart
1384

1485

1586
def read_notes(notes):
@@ -19,7 +90,7 @@ def read_notes(notes):
1990
:return: dict - a user shopping cart dictionary.
2091
"""
2192

22-
pass
93+
return dict.fromkeys(notes, 1)
2394

2495

2596
def update_recipes(ideas, recipe_updates):
@@ -30,7 +101,8 @@ def update_recipes(ideas, recipe_updates):
30101
:return: dict - updated "recipe ideas" dict.
31102
"""
32103

33-
pass
104+
ideas.update(recipe_updates)
105+
return ideas
34106

35107

36108
def sort_entries(cart):
@@ -40,7 +112,7 @@ def sort_entries(cart):
40112
:return: dict - users shopping cart sorted in alphabetical order.
41113
"""
42114

43-
pass
115+
return dict(sorted(cart.items()))
44116

45117

46118
def send_to_store(cart, aisle_mapping):
@@ -50,8 +122,12 @@ def send_to_store(cart, aisle_mapping):
50122
:param aisle_mapping: dict - aisle and refrigeration information dictionary.
51123
:return: dict - fulfillment dictionary ready to send to store.
52124
"""
125+
fulfillment_cart = {}
53126

54-
pass
127+
for key in cart.keys():
128+
fulfillment_cart[key] = [cart[key]] + aisle_mapping[key]
129+
130+
return dict(sorted(fulfillment_cart.items(), reverse=True))
55131

56132

57133
def update_store_inventory(fulfillment_cart, store_inventory):
@@ -62,4 +138,9 @@ def update_store_inventory(fulfillment_cart, store_inventory):
62138
:return: dict - store_inventory updated.
63139
"""
64140

65-
pass
141+
for key, values in fulfillment_cart.items():
142+
store_inventory[key][0] = store_inventory[key][0] - values[0]
143+
if store_inventory[key][0] == 0:
144+
store_inventory[key][0] = 'Out of Stock'
145+
146+
return store_inventory

exercises/concept/mecha-munch-management/dict_methods_test.py

Lines changed: 23 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import unittest
22
import pytest
33
from collections import OrderedDict
4-
from dict_methods import (add_item,
5-
read_notes,
6-
update_recipes,
7-
sort_entries,
8-
send_to_store,
9-
update_store_inventory)
10-
4+
from dict_methods import (
5+
add_item,
6+
read_notes,
7+
update_recipes,
8+
sort_entries,
9+
send_to_store,
10+
update_store_inventory,
11+
)
12+
13+
from dict_methods_test_data import (
14+
add_item_data,
15+
read_notes_data,
16+
update_recipes_data,
17+
sort_entries_data,
18+
send_to_store_data,
19+
update_store_inventory_data,
20+
)
1121

1222
class MechaMunchManagementTest(unittest.TestCase):
1323

1424
@pytest.mark.task(taskno=1)
1525
def test_add_item(self):
16-
input_data = [
17-
({'Apple': 1, 'Banana': 4 }, ('Apple', 'Banana', 'Orange')),
18-
({'Orange': 1, 'Raspberry': 1, 'Blueberries': 10}, ['Raspberry', 'Blueberries', 'Raspberry']),
19-
({'Broccoli': 1, 'Banana': 1}, ('Broccoli', 'Kiwi', 'Kiwi', 'Kiwi', 'Melon', 'Apple', 'Banana', 'Banana'))
20-
]
21-
22-
output_data = [{'Apple': 2, 'Banana': 5, 'Orange': 1},
23-
{'Orange': 1, 'Raspberry': 3, 'Blueberries': 11},
24-
{'Broccoli': 2, 'Banana': 3, 'Kiwi': 3, 'Melon': 1, 'Apple': 1}]
25-
26-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
26+
for variant, (input_data, expected) in enumerate(add_item_data, start=1):
2727
with self.subTest(f'variation #{variant}', input_data=input_data, expected=expected):
2828
actual_result = add_item(input_data[0], input_data[1])
2929
error_msg= (f'Called add_item({input_data[0]}, {input_data[1]}). '
@@ -34,13 +34,7 @@ def test_add_item(self):
3434

3535
@pytest.mark.task(taskno=2)
3636
def test_read_notes(self):
37-
input_data = [('Apple', "Banana"), ('Orange', 'Raspberry', 'Blueberries'),
38-
['Broccoli', 'Kiwi', 'Melon', 'Apple', 'Banana']]
39-
40-
output_data = [{'Apple': 1, 'Banana': 1}, {'Orange': 1, 'Raspberry': 1, 'Blueberries': 1},
41-
{'Broccoli': 1, 'Kiwi': 1, 'Melon': 1, 'Apple': 1, 'Banana': 1}]
42-
43-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
37+
for variant, (input_data, expected) in enumerate(read_notes_data, start=1):
4438
with self.subTest(f'variation #{variant}', input_data=input_data, expected=expected):
4539
actual_result = read_notes(input_data)
4640
error_msg = (f'Called read_notes({input_data}). '
@@ -51,36 +45,7 @@ def test_read_notes(self):
5145

5246
@pytest.mark.task(taskno=3)
5347
def test_update_recipes(self):
54-
input_data = [
55-
({'Banana Bread' : {'Banana': 1, 'Apple': 1, 'Walnuts': 1, 'Flour': 1, 'Eggs': 2, 'Butter': 1},
56-
'Raspberry Pie' : {'Raspberry': 1, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1}},
57-
(('Banana Bread', {'Banana': 4, 'Walnuts': 2, 'Flour': 1, 'Butter': 1, 'Milk': 2, 'Eggs': 3}),)),
58-
59-
({'Apple Pie': {'Apple': 1, 'Pie Crust': 1, 'Cream Custard': 1},
60-
'Blueberry Pie': {'Blueberries': 1, 'Pie Crust': 1, 'Cream Custard': 1}},
61-
(('Blueberry Pie', {'Blueberries': 2, 'Pie Crust': 1, 'Cream Custard': 1}),
62-
('Apple Pie', {'Apple': 1, 'Pie Crust': 1, 'Cream Custard': 1}))),
63-
64-
({'Banana Bread' : {'Banana': 1, 'Apple': 1, 'Walnuts': 1, 'Flour': 1, 'Eggs': 2, 'Butter': 1},
65-
'Raspberry Pie' : {'Raspberry': 1, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1},
66-
'Pasta Primavera': {'Eggs': 1, 'Carrots': 1, 'Spinach': 2, 'Tomatoes': 3, 'Parmesan': 2, 'Milk': 1, 'Onion': 1}},
67-
(('Raspberry Pie', {'Raspberry': 3, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1, 'Whipped Cream': 2}),
68-
('Pasta Primavera', {'Eggs': 1, 'Mixed Veggies': 2, 'Parmesan': 2, 'Milk': 1, 'Spinach': 1, 'Bread Crumbs': 1}),
69-
('Blueberry Crumble', {'Blueberries': 2, 'Whipped Creme': 2, 'Granola Topping': 2, 'Yogurt': 3})))
70-
]
71-
72-
output_data = [
73-
{'Banana Bread': {'Banana': 4, 'Walnuts': 2, 'Flour': 1, 'Butter': 1, 'Milk': 2, 'Eggs': 3},
74-
'Raspberry Pie': {'Raspberry': 1, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1}},
75-
{'Apple Pie': {'Apple': 1, 'Pie Crust': 1, 'Cream Custard': 1},
76-
'Blueberry Pie': {'Blueberries': 2, 'Pie Crust': 1, 'Cream Custard': 1}},
77-
{'Banana Bread': {'Banana': 1, 'Apple': 1, 'Walnuts': 1, 'Flour': 1, 'Eggs': 2, 'Butter': 1},
78-
'Raspberry Pie': {'Raspberry': 3, 'Orange': 1, 'Pie Crust': 1, 'Cream Custard': 1, 'Whipped Cream': 2},
79-
'Pasta Primavera': {'Eggs': 1, 'Mixed Veggies': 2, 'Parmesan': 2, 'Milk': 1, 'Spinach': 1, 'Bread Crumbs': 1},
80-
'Blueberry Crumble': {'Blueberries': 2, 'Whipped Creme': 2, 'Granola Topping': 2, 'Yogurt': 3}}
81-
]
82-
83-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
48+
for variant, (input_data, expected) in enumerate(update_recipes_data, start=1):
8449
with self.subTest(f'variation #{variant}', input_data=input_data, expected=expected):
8550
actual_result = update_recipes(input_data[0], input_data[1])
8651
error_msg = (f'Called update_recipes({input_data[0]}, {input_data[1]}). '
@@ -91,21 +56,7 @@ def test_update_recipes(self):
9156

9257
@pytest.mark.task(taskno=4)
9358
def test_sort_entries(self):
94-
input_data = [
95-
{'Banana': 4, 'Apple': 2, 'Orange': 1, 'Pear': 12},
96-
{'Apple': 3, 'Orange': 5, 'Banana': 1, 'Avocado': 2},
97-
{'Orange': 3, 'Banana': 2, 'Apple': 1},
98-
{'Apple': 2, 'Raspberry': 2, 'Blueberries': 5, 'Broccoli' : 2, 'Kiwi': 1, 'Melon': 4}
99-
]
100-
101-
output_data = [
102-
{'Apple': 2, 'Banana': 4, 'Orange': 1, 'Pear': 12},
103-
{'Apple': 3, 'Avocado': 2, 'Banana': 1, 'Orange': 5},
104-
{'Apple': 1, 'Banana': 2, 'Orange': 3},
105-
{'Apple' : 2, 'Blueberries': 5, 'Broccoli': 2, 'Kiwi': 1, 'Melon': 4, 'Raspberry': 2}
106-
]
107-
108-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
59+
for variant, (input_data, expected) in enumerate(sort_entries_data, start=1):
10960
with self.subTest(f'variation #{variant}', input_data=input_data, expecred=expected):
11061
actual_result = sort_entries(input_data)
11162
error_msg = (f'Called sort_entries({input_data}). '
@@ -119,49 +70,7 @@ def test_sort_entries(self):
11970

12071
@pytest.mark.task(taskno=5)
12172
def test_send_to_store(self):
122-
input_data = [
123-
({'Banana': 3, 'Apple': 2, 'Orange': 1, 'Milk': 2},
124-
{'Banana': ['Aisle 5', False], 'Apple': ['Aisle 4', False],
125-
'Orange': ['Aisle 4', False], 'Milk': ['Aisle 2', True]}),
126-
127-
({'Kiwi': 3, 'Juice': 5, 'Yoghurt': 2, 'Milk': 5},
128-
{'Kiwi': ['Aisle 6', False], 'Juice': ['Aisle 5', False],
129-
'Yoghurt': ['Aisle 2', True], 'Milk': ['Aisle 2', True]}),
130-
131-
({'Apple': 2, 'Raspberry': 2, 'Blueberries': 5,
132-
'Broccoli': 2, 'Kiwi': 1, 'Melon': 4},
133-
134-
{'Apple': ['Aisle 1', False], 'Raspberry': ['Aisle 6', False],
135-
'Blueberries': ['Aisle 6', False], 'Broccoli': ['Aisle 3', False],
136-
'Kiwi': ['Aisle 6', False], 'Melon': ['Aisle 6', False]}),
137-
138-
({'Orange': 1},
139-
{'Banana': ['Aisle 5', False], 'Apple': ['Aisle 4', False],
140-
'Orange': ['Aisle 4', False], 'Milk': ['Aisle 2', True]}),
141-
142-
({'Banana': 3, 'Apple': 2, 'Orange': 1},
143-
{'Banana': ['Aisle 5', False], 'Apple': ['Aisle 4', False],
144-
'Orange': ['Aisle 4', False], 'Milk': ['Aisle 2', True]}),
145-
]
146-
147-
output_data = [
148-
{'Orange': [1, 'Aisle 4', False], 'Milk': [2, 'Aisle 2', True],
149-
'Banana': [3, 'Aisle 5', False], 'Apple': [2, 'Aisle 4', False]},
150-
151-
{'Yoghurt': [2, 'Aisle 2', True], 'Milk': [5, 'Aisle 2', True],
152-
'Kiwi': [3, 'Aisle 6', False], 'Juice': [5, 'Aisle 5', False]},
153-
154-
{'Raspberry': [2, 'Aisle 6', False], 'Melon': [4, 'Aisle 6', False],
155-
'Kiwi': [1, 'Aisle 6', False], 'Broccoli': [2, 'Aisle 3', False],
156-
'Blueberries': [5, 'Aisle 6', False], 'Apple': [2, 'Aisle 1', False]},
157-
158-
{'Orange': [1, 'Aisle 4', False]},
159-
160-
{'Orange': [1, 'Aisle 4', False], 'Banana': [3, 'Aisle 5', False],
161-
'Apple': [2, 'Aisle 4', False]},
162-
]
163-
164-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
73+
for variant, (input_data, expected) in enumerate(send_to_store_data, start=1):
16574
with self.subTest(f'variation #{variant}', input_data=input_data, expected=expected):
16675
actual_result = send_to_store(input_data[0], input_data[1])
16776
error_msg = (f'Called send_to_store({input_data[0]}, {input_data[1]}). '
@@ -175,36 +84,7 @@ def test_send_to_store(self):
17584

17685
@pytest.mark.task(taskno=6)
17786
def test_update_store_inventory(self):
178-
input_data = [
179-
({'Orange': [1, 'Aisle 4', False], 'Milk': [2, 'Aisle 2', True],
180-
'Banana': [3, 'Aisle 5', False], 'Apple': [2, 'Aisle 4', False]},
181-
{'Banana': [15, 'Aisle 5', False], 'Apple': [12, 'Aisle 4', False],
182-
'Orange': [1, 'Aisle 4', False], 'Milk': [4, 'Aisle 2', True]}),
183-
184-
({'Kiwi': [3, 'Aisle 6', False]},{'Kiwi': [3, 'Aisle 6', False], 'Juice': [5, 'Aisle 5', False],
185-
'Yoghurt': [2, 'Aisle 2', True], 'Milk': [5, 'Aisle 2', True]}),
186-
187-
({'Kiwi': [1, 'Aisle 6', False], 'Melon': [4, 'Aisle 6', False], 'Apple': [2, 'Aisle 1', False],
188-
'Raspberry': [2, 'Aisle 6', False], 'Blueberries': [5, 'Aisle 6', False],
189-
'Broccoli': [1, 'Aisle 3', False]},
190-
{'Apple': [2, 'Aisle 1', False], 'Raspberry': [5, 'Aisle 6', False],
191-
'Blueberries': [10, 'Aisle 6', False], 'Broccoli': [4, 'Aisle 3', False],
192-
'Kiwi': [1, 'Aisle 6', False], 'Melon': [8, 'Aisle 6', False]})
193-
]
194-
195-
output_data = [
196-
{'Banana': [12, 'Aisle 5', False], 'Apple': [10, 'Aisle 4', False],
197-
'Orange': ['Out of Stock', 'Aisle 4', False], 'Milk': [2, 'Aisle 2', True]},
198-
199-
{'Juice': [5, 'Aisle 5', False], 'Yoghurt': [2, 'Aisle 2', True],
200-
'Milk': [5, 'Aisle 2', True], 'Kiwi': ["Out of Stock", 'Aisle 6', False]},
201-
202-
{'Kiwi': ['Out of Stock', 'Aisle 6', False], 'Melon': [4, 'Aisle 6', False],
203-
'Apple': ['Out of Stock', 'Aisle 1', False], 'Raspberry': [3, 'Aisle 6', False],
204-
'Blueberries': [5, 'Aisle 6', False], 'Broccoli': [3, 'Aisle 3', False]}
205-
]
206-
207-
for variant, (input_data, expected) in enumerate(zip(input_data, output_data), start=1):
87+
for variant, (input_data, expected) in enumerate(update_store_inventory_data, start=1):
20888
with self.subTest(f'variation #{variant}', input_data=input_data, expected=expected):
20989
actual_result = update_store_inventory(input_data[0], input_data[1])
21090
error_msg = (f'Called update_store_inventory({input_data[0]}, {input_data[1]}). '

0 commit comments

Comments
 (0)