TEST(CircularBuffer, PrintBoundary) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); removeFromQueue(buffer->Capacity() - 2); buffer->Put(888); fillTheQueue(300, buffer->Capacity() - 1); buffer->Print(&mock); // const char* expected = "Circular buffer content:\n" // "<888, 300, 301, 302, 303>\n"; // CHECK_EQUAL(expected, mock.getOutput()); }
TEST(CircularBuffer, EmptyToFullToEmpty) { fillTheQueue(100, buffer->Capacity()); CHECK(buffer->IsFull()); removeFromQueue(buffer->Capacity()); CHECK(buffer->IsEmpty()); }
TEST(CircularBuffer, FillEmptyThenPrint) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); removeFromQueue(buffer->Capacity()); buffer->Print(&mock); // const char* expected = "Circular buffer content:\n" // "<>\n"; // CHECK_EQUAL(expected, mock.getOutput()); }
TEST(CircularBuffer, PrintNotYetWrappedAndIsFull) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Print(&mock); // const char* expected = "Circular buffer content:\n" // "<200, 201, 202, 203, 204>\n"; // CHECK_EQUAL(expected, mock.getOutput()); }
TEST(CircularBuffer, PutToFull) { int capacity = buffer->Capacity(); fillTheQueue(900, capacity); buffer->Put(9999); for (int i = 0; i < buffer->Capacity() - 1; i++) LONGS_EQUAL(i+900+1, buffer->Get()); LONGS_EQUAL(9999, buffer->Get()); CHECK(buffer->IsEmpty()); }
TEST(CircularBuffer, PrintWrappedAndFullOverwriteOldest) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Put(9999); buffer->Print(&mock); // const char* expected = "Circular buffer content:\n" // "<201, 202, 203, 204, 9999>\n"; // CHECK_EQUAL(expected, mock.getOutput()); }
TEST(CircularBuffer, WrapAround) { fillTheQueue(100, buffer->Capacity()); CHECK(buffer->IsFull()); LONGS_EQUAL(100, buffer->Get()); CHECK(!buffer->IsFull()); buffer->Put(1000); CHECK(buffer->IsFull()); removeFromQueue(buffer->Capacity() - 1); LONGS_EQUAL(1000, buffer->Get()); CHECK(buffer->IsEmpty()); }
TEST(CircularBuffer, PrintWrappedAndIsFullOldestToNewest) { MockPrinter mock; fillTheQueue(200, buffer->Capacity()); buffer->Get(); buffer->Put(999); buffer->Print(&mock); char* expected = "Circular buffer content:\n" "<201, 202, 203, 204, 999>\n"; CHECK_EQUAL(expected, mock.getOutput()); }
TEST(CircularBuffer, IsFull) { fillTheQueue(0, buffer->Capacity()); CHECK(buffer->IsFull()); }