Verifying Output with a Spy

In this section, we’ll look at a utility module, the CircularBuffer. A CircularBuffer can be created with a specified capacity; it can have integers added to it and removed from it. It behaves as a first-in first-out data structure. Some of the situations a CircularBuffer might find itself in are shown in Figure 19, CircularBuffer.

The CircularBuffer also must print itself out, oldest entry to newest, and not disturb the contents of the buffer. Given all the special cases, this is not quite as easy as it sounds. We’re coming into this problem with a working CircularBuffer and have to add the print capability. To get our test fixture in place, let’s start with the simplest case, printing an empty buffer. When ...

Get Test Driven Development for Embedded C now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.