Task Description: Implement a Shopping Cart Functionality
Objective:
Create a shopping cart system that allows users to add items, remove items, view the cart, and calculate the total price of items in the cart.
Requirements:
Shopping Cart Class (ShoppingCart)
Implement a class ShoppingCart in the /app/ directory.
The class should have the following methods:
add_item(item: str, price: float):
Adds an item to the cart with a given price.
If the item is already in the cart, increase the quantity by one.
remove_item(item: str):
Removes one instance of the specified item from the cart.
If the item is not in the cart, do nothing.
If the item quantity reaches zero, it should be removed from the cart entirely.
view_cart() -> dict:
Returns a dictionary representing the items in the cart with their quantities and prices.
Example format: { "item_name": {"quantity": 2, "price": 9.99}, ... }
calculate_total() -> float:
Returns the total price of all items in the cart, taking into account the quantity of each item.
Data Structure:
Internally, the shopping cart should maintain a storage structure (e.g., a dictionary) to keep track of items, quantities, and prices.
Test Cases:
Ensure the implementation passes the following scenarios:
Adding new items and verifying that they are stored correctly.
Adding duplicate items and checking that the quantity is incremented.
Removing items and verifying that the quantity decreases or is removed entirely.
Correctly viewing the cart.
Accurately calculating the total price of items in the cart.
Implement the ShoppingCart class according to the defined specifications in the /app/ directory and ensure all relevant test cases covered in the test code pass successfully.