Skip to content

Commit 0c649c3

Browse files
committed
subitting assignments 1 & 2
1 parent cc6d9fd commit 0c649c3

33 files changed

+10115
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# squarer.py
2+
class Squarer(object):
3+
4+
@staticmethod
5+
def calc(operand):
6+
return operand*operand
7+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# test2.py
2+
import unittest
3+
4+
from squarer import Squarer
5+
6+
7+
class SquarerTest(unittest.TestCase):
8+
9+
def test_positive_numbers(self):
10+
11+
squares = {
12+
1: 1,
13+
2: 4,
14+
3: 9,
15+
12: 144,
16+
100: 10000,
17+
}
18+
19+
for num, square in squares.items():
20+
self.assertEqual(square, Squarer.calc(num), "Squaring {}".format(num));
21+
22+
def test_negative_numbers(self):
23+
24+
squares = {
25+
-1: 1,
26+
-2: 4,
27+
-3: 9,
28+
-12: 144,
29+
-100: 10000,
30+
}
31+
32+
for num, square in squares.items():
33+
self.assertEqual(square, Squarer.calc(num), "Squaring {}".format(num));
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# test.py
2+
from squarer import Squarer
3+
4+
5+
class SquarerTest(object):
6+
7+
@staticmethod
8+
def test_positive_numbers():
9+
10+
squares = {
11+
1: 1,
12+
2: 4,
13+
3: 9,
14+
12: 144,
15+
100: 10000,
16+
}
17+
18+
for num, square in squares.items():
19+
result = Squarer.calc(num)
20+
21+
if result != square:
22+
print("Squared {} and got {} but expected {}".format(num, result, square))
23+
24+
@staticmethod
25+
def test_negative_numbers():
26+
27+
squares = {
28+
-1: 1,
29+
-2: 4,
30+
-3: 9,
31+
-12: 144,
32+
-100: 10000,
33+
}
34+
35+
for num, square in squares.items():
36+
result = Squarer.calc(num)
37+
38+
if result != square:
39+
print("Squared {} and got {} but expected {}".format(num, result, square))
40+
41+
42+
if __name__ == "__main__":
43+
SquarerTest.test_positive_numbers()
44+
SquarerTest.test_negative_numbers()
45+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Grading
2+
=======
3+
4+
For assignment 1, you will need to supply your own unit_tests.py 
5+
and integration_test.py files.
6+
7+
The assignment is graded as follows:
8+
1. Run the student unit_tests
9+
2. Run coverage and linting using the regular batch file.

students/kevin_cavanaugh/Lesson01/assignment/inventory_management/__init__.py

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'''
2+
Electric appliances class
3+
'''
4+
5+
from inventory_management.inventory_class import Inventory
6+
7+
8+
class ElectricAppliances(Inventory):
9+
'''
10+
class for electrical appliances
11+
'''
12+
13+
def __init__(self, product_code, description, market_price,
14+
rental_price, brand, voltage):
15+
'''
16+
Creates common instance variables from the parent class
17+
:param product_code:
18+
:param description:
19+
:param market_price:
20+
:param rental_price:
21+
:param brand:
22+
:param voltage:
23+
'''
24+
Inventory.__init__(self, product_code, description,
25+
market_price, rental_price)
26+
27+
self.brand = brand
28+
self.voltage = voltage
29+
30+
def return_as_dictionary(self):
31+
'''
32+
returns electrical appliances dictionary
33+
:return:
34+
'''
35+
output_dict = super().return_as_dictionary()
36+
output_dict['brand'] = self.brand
37+
output_dict['voltage'] = self.voltage
38+
39+
return output_dict
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'''
2+
Furniture class
3+
'''
4+
from inventory_management.inventory_class import Inventory
5+
6+
7+
class Furniture(Inventory):
8+
'''
9+
class of inventory for furniture
10+
'''
11+
12+
def __init__(self, product_code, description, market_price,
13+
rental_price, material, size):
14+
'''
15+
Creates common instance variables from the parent class
16+
:param product_code:
17+
:param description:
18+
:param market_price:
19+
:param rental_price:
20+
:param material:
21+
:param size:
22+
'''
23+
Inventory.__init__(self, product_code, description,
24+
market_price, rental_price)
25+
26+
self.material = material
27+
self.size = size
28+
29+
def return_as_dictionary(self):
30+
'''
31+
return furniture as a dictionary
32+
:return:
33+
'''
34+
output_dict = super().return_as_dictionary()
35+
output_dict['material'] = self.material
36+
output_dict['size'] = self.size
37+
38+
return output_dict
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'''
2+
Inventory class
3+
'''
4+
5+
6+
class Inventory:
7+
'''
8+
class for creating inventory objects
9+
'''
10+
11+
def __init__(self, product_code, description,
12+
market_price, rental_price):
13+
'''
14+
construct inventory object
15+
:param product_code:
16+
:param description:
17+
:param market_price:
18+
:param rental_price:
19+
'''
20+
self.product_code = product_code
21+
self.description = description
22+
self.market_price = market_price
23+
self.rental_price = rental_price
24+
25+
def return_as_dictionary(self):
26+
'''
27+
return inventory object as a dictionary
28+
:return:
29+
'''
30+
output_dict = {
31+
'product_code': self.product_code,
32+
'description': self.description,
33+
'market_price': self.market_price,
34+
'rental_price': self.rental_price
35+
}
36+
37+
return output_dict
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
'''
2+
Launches the user interface for the inventory management system
3+
'''
4+
import sys
5+
from inventory_management import market_prices
6+
from inventory_management import inventory_class
7+
from inventory_management import furniture_class
8+
from inventory_management import electric_appliances_class as ea
9+
10+
11+
def main_menu(user_prompt=None):
12+
'''
13+
produces main menu for user interface
14+
:param user_prompt:
15+
:return:
16+
'''
17+
valid_prompts = {"1": add_new_item,
18+
"2": item_info,
19+
"q": exit_program}
20+
options = list(valid_prompts.keys())
21+
22+
while user_prompt not in valid_prompts:
23+
options_str = ("{}" + ", {}" * (len(options)-1)).format(*options)
24+
print(f"Please choose from the following options ({options_str}):")
25+
print("1. Add a new item to the inventory")
26+
print("2. Get item information")
27+
print("q. Quit")
28+
user_prompt = input(">")
29+
return valid_prompts.get(user_prompt)
30+
31+
32+
def get_price(item_code):
33+
'''
34+
prints 'Get price'
35+
:return:
36+
'''
37+
38+
price = FULL_INVENTORY[item_code]['rental_price']
39+
40+
return price
41+
42+
43+
def add_new_item():
44+
'''
45+
add new inventory item
46+
:return:
47+
'''
48+
49+
item_code = input("Enter item code: ")
50+
item_description = input("Enter item description: ")
51+
item_rental_price = input("Enter item rental price: ")
52+
53+
# Get price from the market prices module
54+
item_price = market_prices.get_latest_prices()
55+
56+
is_furniture = input("Is this item a piece of furniture? (Y/N): ")
57+
if is_furniture.lower() == "y":
58+
item_material = input("Enter item material: ")
59+
item_size = input("Enter item size (S,M,L,XL): ")
60+
new_item = furniture_class.Furniture(
61+
item_code, item_description, item_price,
62+
item_rental_price, item_material, item_size)
63+
else:
64+
is_electric_appliance = input(
65+
"Is this item an electric appliance? (Y/N): ")
66+
if is_electric_appliance.lower() == "y":
67+
item_brand = input("Enter item brand: ")
68+
item_voltage = input("Enter item voltage: ")
69+
new_item = ea.ElectricAppliances(
70+
item_code, item_description, item_price,
71+
item_rental_price, item_brand, item_voltage)
72+
else:
73+
new_item = inventory_class.Inventory(
74+
item_code, item_description, item_price, item_rental_price)
75+
FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
76+
print("New inventory item added")
77+
return FULL_INVENTORY[item_code]
78+
79+
def item_info():
80+
'''
81+
prints info for inventory item
82+
:return:
83+
'''
84+
item_code = input("Enter item code: ")
85+
if item_code in FULL_INVENTORY:
86+
print_dict = FULL_INVENTORY[item_code]
87+
output = []
88+
for key, value in print_dict.items():
89+
print("{}:{}".format(key, value))
90+
output.append(print_dict)
91+
else:
92+
print("Item not found in inventory")
93+
output = "Item not found in inventory"
94+
95+
return output
96+
97+
98+
def exit_program():
99+
'''
100+
exits program
101+
:return:
102+
'''
103+
sys.exit()
104+
105+
106+
FULL_INVENTORY = {}
107+
108+
if __name__ == '__main__':
109+
110+
while True:
111+
print(FULL_INVENTORY)
112+
main_menu()()
113+
input("Press Enter to continue...........")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
Raise an exception to force the user to Mock its output
3+
"""
4+
5+
6+
def get_latest_prices():
7+
"""
8+
get the latest price for an inventory item
9+
"""
10+
return 24

0 commit comments

Comments
 (0)