Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 29, 2015 14:09
Show Gist options
  • Save up1/28bf74ce7dffb5f3db80 to your computer and use it in GitHub Desktop.
Save up1/28bf74ce7dffb5f3db80 to your computer and use it in GitHub Desktop.
TDD with C++
TEST(CircularBuffer, empty_after_create)
{
    CHECK_TRUE(buffer->isEmpty());
}
void CircularBuffer::put(int number)
{
   values[index] = number;
   index++;
   count++;
}
int CircularBuffer::get()
{
    int value = values[outdex];
    count--;
    outdex++;
    return value;
}
bool CircularBuffer::isEmpty() const
{
    return true;
}
TEST(CircularBuffer, not_empty_after_put)
{
    buffer->put(10046);
    CHECK_FALSE(buffer->isEmpty());
}
bool CircularBuffer::isEmpty() const
{
    return count == 0;
}
void CircularBuffer::put(int number)
{
   count++;
}
TEST(CircularBuffer, transition_to_empty)
{
    buffer->put(4567);
    buffer->get();
    CHECK_TRUE(buffer->isEmpty());
}
int CircularBuffer::get()
{
    count—;
    return 99999;
}
TEST(CircularBuffer, get_put_one_value)
{
    buffer->put(42);
    LONGS_EQUAL(42, buffer->get());
}
void CircularBuffer::put(int number)
{
   index++;
   count++;
}
int CircularBuffer::get()
{
   count--;
   outdex++;
   return 42;
}
TEST(CircularBuffer, get_put_a_few_is_fifo)
{
    buffer->put(1);
    buffer->put(2);
    buffer->put(3);
    LONGS_EQUAL(1, buffer->get());
    LONGS_EQUAL(2, buffer->get());
    LONGS_EQUAL(3, buffer->get());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment