From the course: Test-Driven Development in C++
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Add and apply discounts - C++ Tutorial
From the course: Test-Driven Development in C++
Add and apply discounts
- [Instructor] So for this test case, I need to add a method to the checkout to allow me to submit a discount rule. A discount has three parameters: the item type, the number of items required for the discount, and the discounted price. So I'm going to add a method called AddDiscount, which takes those three parameters. I'm in the red phase now, so I'll start by implementing a failing unit test that tries to call that new method. Okay, so test fixture checkout test can add discount. Checkout dot add discount, the item, the item count, and the discount price. Okay, so I added a test which calls AddDiscount passing in the A type, with three for the number of A's, and two for the discounted price. The test is failing to compile because the AddDiscount method doesn't exist in the checkout class yet. I'm in the green phase now, so I'm gonna add that method to the checkout class to make the test pass. As always, this should be the simplest implementation possible to make that test pass. So…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Overview, setup, and the first test case6m 10s
-
(Locked)
Add items, add item prices, and calculate the current total9m 56s
-
(Locked)
Add multiple items and calculate the total3m 49s
-
(Locked)
Add and apply discounts19m 37s
-
(Locked)
Throw an exception when adding an item with no price3m 2s
-
(Locked)
-
-
-