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

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…

Contents