April 2011
Intermediate to advanced
356 pages
8h 55m
English
Let’s use our random minute generator for the randomized light schedule feature. The scheduler will have unpredictable results because of its unpredictable indirect input from RandomMinute_Get. When production code depends on something unpredictable, it’s time to substitute in a test double. We have a problem; the binding of the LightScheduler to RandomMinute_Get is done by the linker, as you can see by looking at the interface of RandomMinute:
| t0/include/HomeAutomation/RandomMinute.h | |
| | void RandomMinute_Create(int bound); |
| | int RandomMinute_Get(void); |
Before we refactor the interface to allow function pointer substitution, let’s design the test for the randomized schedule.
| t0/tests/HomeAutomation/LightSchedulerRandomizeTest.cpp ... |