Ringbuffer added
This commit is contained in:
60
test/ringbuffer.cpp
Normal file
60
test/ringbuffer.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "../sequential/ringbuffer.hpp"
|
||||
#include "testutil.hpp"
|
||||
|
||||
bool TestInsertion()
|
||||
{
|
||||
std::size_t const testSize = 512u;
|
||||
|
||||
std::vector<unsigned> truth;
|
||||
truth.resize(testSize);
|
||||
RingBuffer<unsigned> ringBuffer(512u);
|
||||
|
||||
for(std::size_t i = 0; i < testSize; ++i)
|
||||
{
|
||||
truth[i] = Util::GetRandomNumber();
|
||||
ringBuffer.Push(truth[i]);
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < testSize; ++i)
|
||||
{
|
||||
if(truth[i] != ringBuffer.Pop())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestWrapAround()
|
||||
{
|
||||
std::size_t const testSize = 32u;
|
||||
|
||||
RingBuffer<unsigned> ringBuffer(testSize);
|
||||
for(std::size_t i = 0; i < testSize / 2u; ++i)
|
||||
{
|
||||
ringBuffer.Push(42u);
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < testSize; ++i)
|
||||
{
|
||||
ringBuffer.Push(i);
|
||||
}
|
||||
|
||||
for(std::size_t i = 0; i < testSize; ++i)
|
||||
{
|
||||
if(ringBuffer.Pop() != i)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
Test::Execute(TestInsertion, "Insertion test");
|
||||
Test::Execute(TestWrapAround, "Wrap around test");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user