Last active
August 29, 2015 14:09
-
-
Save up1/28bf74ce7dffb5f3db80 to your computer and use it in GitHub Desktop.
TDD with C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(CircularBuffer, empty_after_create) | |
{ | |
CHECK_TRUE(buffer->isEmpty()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CircularBuffer::put(int number) | |
{ | |
values[index] = number; | |
index++; | |
count++; | |
} | |
int CircularBuffer::get() | |
{ | |
int value = values[outdex]; | |
count--; | |
outdex++; | |
return value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CircularBuffer::isEmpty() const | |
{ | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(CircularBuffer, not_empty_after_put) | |
{ | |
buffer->put(10046); | |
CHECK_FALSE(buffer->isEmpty()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool CircularBuffer::isEmpty() const | |
{ | |
return count == 0; | |
} | |
void CircularBuffer::put(int number) | |
{ | |
count++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(CircularBuffer, transition_to_empty) | |
{ | |
buffer->put(4567); | |
buffer->get(); | |
CHECK_TRUE(buffer->isEmpty()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int CircularBuffer::get() | |
{ | |
count—; | |
return 99999; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST(CircularBuffer, get_put_one_value) | |
{ | |
buffer->put(42); | |
LONGS_EQUAL(42, buffer->get()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CircularBuffer::put(int number) | |
{ | |
index++; | |
count++; | |
} | |
int CircularBuffer::get() | |
{ | |
count--; | |
outdex++; | |
return 42; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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