diff options
author | Eugene Sandulenko | 2016-05-23 16:11:48 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-05-23 16:36:34 +0200 |
commit | 5a8eb1c9d699f69bfa0406a2d80f7576e7eb5136 (patch) | |
tree | 1c90d282fdb5e40204190b19d6210954e9748dc3 /test/common | |
parent | 3d89af272b718dd30a60f351149fde95958acfb0 (diff) | |
download | scummvm-rg350-5a8eb1c9d699f69bfa0406a2d80f7576e7eb5136.tar.gz scummvm-rg350-5a8eb1c9d699f69bfa0406a2d80f7576e7eb5136.tar.bz2 scummvm-rg350-5a8eb1c9d699f69bfa0406a2d80f7576e7eb5136.zip |
TESTS: Implement SortedArray test
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/array.h | 41 |
1 files changed, 41 insertions, 0 deletions
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<ListElement *> container(compareInts); + Common::SortedArray<ListElement *>::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()); + } + } + +}; |