Skip to content
Snippets Groups Projects
Commit 6e09243d authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

Merge branch 'feature/add-test-fifo' into 'master'

Test the FIFO implementation

This merge requests adds a simple unit test for UG's FIFO implementation.

See merge request !18
parents 3af88598 6a234737
No related branches found
No related tags found
1 merge request!18Test the FIFO implementation
Pipeline #
add_subdirectory(test)
# normal headers
set(lowinclude_HEADERS heaps.h ugenv.h ugstruct.h misc.h debug.h ugtypes.h
general.h dimension.h boxtree.h ugtimer.h scan.h
......
dune_add_test(SOURCES test-fifo.cc)
target_link_libraries(test-fifo ugL2)
#include "config.h"
#include <memory>
#include <dune/common/test/testsuite.hh>
#include "../fifo.h"
using namespace Dune;
TestSuite test_fifo()
{
TestSuite test;
using namespace UG;
FIFO fifo;
const INT size = 32;
int items[size];
for (int i = 0; i < size; ++i)
items[i] = i;
auto buffer = std::make_unique<void*[]>(size);
{
const auto result = fifo_init(&fifo, buffer.get(), size * sizeof(void*));
test.require(result, "require that fifo_init() suceeds");
}
test.check(fifo_empty(&fifo), "New FIFO must be empty");
test.check(!fifo_full(&fifo), "New FIFO must not be full");
test.check(fifo_out(&fifo) == nullptr, "New FIFO must not return an element");
{
const auto result = fifo_in(&fifo, &items[0]);
test.check(!result, "Inserting an element must succeed");
}
test.check(!fifo_empty(&fifo), "FIFO must not be empty after inserting an element");
test.check(!fifo_full(&fifo), "FIFO must not be full after inserting an element");
{
const auto v = static_cast<int*>(fifo_out(&fifo));
test.check(v == &items[0], "FIFO must return the item inserted before");
}
test.check(fifo_empty(&fifo), "FIFO must be empty after removing the element again");
test.check(!fifo_full(&fifo), "FIFO must not be full after removing the element again");
for (auto& item : items) {
bool result = fifo_in(&fifo, &item);
test.check(!result, "Inserting elemens must succeed");
}
test.check(!fifo_empty(&fifo), "FIFO must not be empty after filling it");
test.check(fifo_full(&fifo), "FIFO must be full after filling it");
{
bool result = fifo_in(&fifo, &items[0]);
test.check(result, "Inserting into a full FIFO must fail");
}
for (auto& item : items) {
const auto v = static_cast<int*>(fifo_out(&fifo));
test.check(v == &item, "FIFO must return correct item");
}
test.check(fifo_empty(&fifo), "FIFO must be empty after removing all elements");
test.check(!fifo_full(&fifo), "FIFO must not be full after removing all elements");
test.check(fifo_out(&fifo) == nullptr, "fifo_out() must return nullptr after removing all elements");
fifo_clear(&fifo);
return test;
}
int main()
{
TestSuite test;
test.subTest(test_fifo());
return test.exit();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment