Implement the following problem statement in python along with test cases. Let’s say you have a Customer class and you want to test calculate bill method of customer class. Bill calculation will depend on list of items customer purchased
class Customer:
def bill(self, items: list) -> float:
# This variant of the prices is presented only as an example
# For a larger number of items it should be imported
price = {"Book1": 12.97,
"Book2": 87.36,
"Book3": 10.73}
total = 0.0
for item in items:
total += price.get(item)
return round(total, 2)
pass
# TEST PART
test_customer = Customer()
test_items_1 = ["Book1"]
test_items_2 = ["Book2", "Book3"]
test_items_3 = ["Book1", "Book3", "Book2", "Book2"]
total_cost_1 = Customer.bill(test_customer, test_items_1)
total_cost_2 = Customer.bill(test_customer, test_items_2)
total_cost_3 = Customer.bill(test_customer, test_items_3)
print(f"Total cost of all items from {test_items_1} is {total_cost_1}")
print(f"Total cost of all items from {test_items_2} is {total_cost_2}")
print(f"Total cost of all items from {test_items_3} is {total_cost_3}")
Comments
Leave a comment