Add price_by_measure member to Item object

This commit is contained in:
KorenLazar
2021-08-16 12:39:28 +03:00
parent 27b45a4999
commit 98dcc1c33d
3 changed files with 18 additions and 20 deletions

View File

@@ -3,11 +3,12 @@ class Item:
A class representing a product in some supermarket.
"""
def __init__(self, name: str, price: float, manufacturer: str, code: str):
def __init__(self, name: str, price: float, price_by_measure: float, code: str, manufacturer: str):
self.name: str = name
self.price: float = price
self.price_by_measure = price_by_measure
self.manufacturer: str = manufacturer
self.code: str = code
def __repr__(self):
return str((self.name, self.price, self.manufacturer, self.code))
return f"\nשם: {self.name}\nמחיר: {self.price}\nיצרן: {self.manufacturer}\nקוד: {self.code}\n"

View File

@@ -120,9 +120,6 @@ class SupermarketChain(object, metaclass=Meta):
"""
This function returns a string containing important information about a given supermarket's product.
"""
return Item(
name=item.find(re.compile(r'ItemN[a]?m[e]?')).text,
price=float(item.find('ItemPrice').text),
manufacturer=item.find(re.compile(r'Manufacture[r]?Name')).text,
code=item.find('ItemCode').text
)
return Item(name=item.find(re.compile(r'ItemN[a]?m[e]?')).text, price=float(item.find('ItemPrice').text),
price_by_measure=float(item.find('UnitOfMeasurePrice').text), code=item.find('ItemCode').text,
manufacturer=item.find(re.compile(r'Manufacture[r]?Name')).text)

View File

@@ -19,7 +19,7 @@ def test_shufersal_promo_type_1():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('פטה פיראוס 20%', 113, '', '')
item = Item('פטה פיראוס 20%', 113, 1, '', '')
assert promo_func(item) == 100
@@ -38,7 +38,7 @@ def test_shufersal_promo_type_2():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('חגיגת גרנולה פ.יבשים500ג', 26.9, '', '')
item = Item('חגיגת גרנולה פ.יבשים500ג', 26.9, 1, '', '')
assert promo_func(item) == 21.52
@@ -57,7 +57,7 @@ def test_shufersal_promo_type_6_1():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('פסטרמה מקסיקנית במשקל', 89, '', '')
item = Item('פסטרמה מקסיקנית במשקל', 89, 1, '', '')
assert promo_func(item) == 89
@@ -76,7 +76,7 @@ def test_shufersal_promo_type_6_2():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('מכונת לוואצה ג\'ולי אדומה', 449, '', '')
item = Item('מכונת לוואצה ג\'ולי אדומה', 449, 1, '', '')
assert promo_func(item) == 449
@@ -95,7 +95,7 @@ def test_shufersal_promo_type_7_1():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('פינצטה 2011 שחורה/כסופה', 14.9, '', '')
item = Item('פינצטה 2011 שחורה/כסופה', 14.9, 1, '', '')
assert promo_func(item) == 7.45
@@ -114,7 +114,7 @@ def test_shufersal_promo_type_7_2():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('יוגורט עיזים 500 גרם', 12.9, '', '')
item = Item('יוגורט עיזים 500 גרם', 12.9, 1, '', '')
assert promo_func(item) == 12.9 * 0.75
@@ -133,7 +133,7 @@ def test_shufersal_promo_type_9_1():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('זיתים מבוקעים פיקנטי540ג', 9.3, '', '')
item = Item('זיתים מבוקעים פיקנטי540ג', 9.3, 1, '', '')
assert promo_func(item) == 9.3 * 0.75
@@ -152,7 +152,7 @@ def test_shufersal_promo_type_9_2():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('שעועית לבנה שופרסל 800גר', 18.9, '', '')
item = Item('שעועית לבנה שופרסל 800גר', 18.9, 1, '', '')
assert promo_func(item) == (18.9 + 10) / 2
@@ -171,7 +171,7 @@ def test_shufersal_promo_type_9_3():
discount_rate=discount_rate,
discounted_price=discounted_price,
)
item = Item('גומיות שחורות 12 יח', 9.9, '', '')
item = Item('גומיות שחורות 12 יח', 9.9, 1, '', '')
assert promo_func(item) == 9.9 * 0.75
@@ -190,7 +190,7 @@ def test_shufersal_promo_type_10_1():
discount_rate=discount_rate,
discounted_price=discounted_price
)
item = Item('טופו טעם טבעי 300 גרם', 10.9, '', '7296073345763')
item = Item('טופו טעם טבעי 300 גרם', 10.9, 1, '7296073345763', '')
assert promo_func(item) == 5
@@ -209,7 +209,7 @@ def test_shufersal_promo_type_10_2():
discount_rate=discount_rate,
discounted_price=discounted_price
)
item = Item('טופו טעם טבעי 300 גרם', 10.9, 'כפרי בריא משק ויילר', '7296073345763')
item = Item('טופו טעם טבעי 300 גרם', 10.9, 1, '7296073345763', 'כפרי בריא משק ויילר')
assert promo_func(item) == 7
@@ -225,7 +225,7 @@ def assert_discount(discounted_price, item_barcode, item_manufacturer, item_name
discount_rate=discount_rate,
discounted_price=discounted_price
)
item = Item(item_name, orig_price, item_manufacturer, item_barcode)
item = Item(item_name, orig_price, 1, item_barcode, item_manufacturer)
assert abs(promo_func(item) - price_after_discount) <= 1e-5, promo_description