From 5a8eb1c9d699f69bfa0406a2d80f7576e7eb5136 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 23 May 2016 16:11:48 +0200 Subject: TESTS: Implement SortedArray test --- test/common/array.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'test/common') diff --git a/test/common/array.h b/test/common/array.h index 64354abc00..7473398058 100644 --- a/test/common/array.h +++ b/test/common/array.h @@ -354,3 +354,44 @@ class ArrayTestSuite : public CxxTest::TestSuite } }; + +struct ListElement { + int value; + + ListElement(int v) : value(v) {} +}; + +static int compareInts(const void *a, const void *b) { + return ((ListElement *)a)->value - ((ListElement *)a)->value; +} + +class SortedArrayTestSuite : public CxxTest::TestSuite { +public: + void test_insert() { + Common::SortedArray container(compareInts); + Common::SortedArray::iterator iter; + + // Fill the container with some random data + container.insert(new ListElement(1)); + return; + + container.insert(new ListElement(7)); + container.insert(new ListElement(8)); + container.insert(new ListElement(3)); + container.insert(new ListElement(5)); + container.insert(new ListElement(4)); + container.insert(new ListElement(9)); + container.insert(new ListElement(2)); + container.insert(new ListElement(6)); + + // Verify contents are correct + iter = container.begin(); + + for (int i = 1; i < 10; i++) { + TS_ASSERT_EQUALS((*iter)->value, i); + ++iter; + TS_ASSERT_DIFFERS(iter, container.end()); + } + } + +}; -- cgit v1.2.3