Welcome to the fifth and final unit of this course, focused on practicing the principles of Test Driven Development (TDD) using C++ and Google Test. We're going to continue building our ShoppingCart system by integrating even more sophisticated features into our class.
In this course, emphasis is placed on hands-on practice, where you'll receive requirements through tests, one at a time. Your task is to write tests AND implement code that makes each test pass, simulating a real-world TDD environment. In previous lessons, tests were provided to guide you, but now it's your turn to define them!
Remember to apply the core concepts of the Red-Green-Refactor cycle while completing these coding exercises. Ask questions if you need any clarification!
- Description: The cart should enforce a maximum quantity limit of 10 for a single type of item, preventing more than this allowed amount from being added.
- Details
- Utilize the
AddItem(item, quantity)method to add items to the cart. - Ensure an exception is raised when adding a quantity that exceeds the limit of 10 for a single item.
- The exception should be of type
std::invalid_argumentwith the message "Maximum quantity exceeded."
- Utilize the
- Examples: Attempting to add
11units of an item should throw astd::invalid_argumentexception indicating "Maximum quantity exceeded."
- Description: When an item is added to the cart, it should be possible to retrieve that item's details using its ID, including the product information and the quantity in the cart.
- Details
- Enable items to be added using the
AddItem()method with specific IDs. - Ensure that
GetItem(id)returns the correct item details, including the quantity, after being added to the cart.
- Enable items to be added using the
- Examples: Adding a
"Book"with ID1and price10and retrieving by ID1should return an object withId: 1, Name: 'Book', Price: 10, Quantity: 1.
- Description: Applying a valid discount code should reduce the total price of items in the cart by the specified discount percentage.
- Details
- Use the
ApplyDiscountCode(code)method to apply a discount. - Support valid discount codes stored in a
std::map, such asHOLIDAY25for a 25% discount. - Update
GetTotal()to reflect the discounted price.
- Use the
- Examples: Applying the discount code
'HOLIDAY25'to a product"Book"with a price of 100 should reduce the total to75.
