diff options
author | Paul Gilbert | 2016-07-26 19:48:14 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-26 19:48:14 -0400 |
commit | 504cf6ecb688a3f1c65a857bffd527d8b0e6ba63 (patch) | |
tree | 0c0d96d4061c11850c851f0fc981c75a58c20515 /test/common/array.h | |
parent | d8c28d15ae553d047b7e571f98727fa79ee143f3 (diff) | |
parent | e19922d181e775791f9105b8be7ff410770ede51 (diff) | |
download | scummvm-rg350-504cf6ecb688a3f1c65a857bffd527d8b0e6ba63.tar.gz scummvm-rg350-504cf6ecb688a3f1c65a857bffd527d8b0e6ba63.tar.bz2 scummvm-rg350-504cf6ecb688a3f1c65a857bffd527d8b0e6ba63.zip |
Merge branch 'master' into xeen
Diffstat (limited to 'test/common/array.h')
-rw-r--r-- | test/common/array.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/test/common/array.h b/test/common/array.h index f0027ec201..2dc67837db 100644 --- a/test/common/array.h +++ b/test/common/array.h @@ -44,6 +44,48 @@ class ArrayTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(iter, array.end()); } + void test_erase_iterator() { + Common::Array<int> array; + Common::Array<int>::iterator iter; + + // Fill the array with some random data + array.push_back(17); + array.push_back(33); + array.push_back(-11); + + iter = array.begin(); + ++iter; + + iter = array.erase(iter); + TS_ASSERT_DIFFERS(iter, array.end()); + TS_ASSERT_EQUALS(*iter, -11); + TS_ASSERT_EQUALS(array.size(), (unsigned int)2); + TS_ASSERT_EQUALS(array[0], 17); + TS_ASSERT_EQUALS(array[1], -11); + } + + void test_insert_iterator() { + Common::Array<int> array; + Common::Array<int>::iterator iter; + + // Fill the array with some random data + array.push_back(17); + array.push_back(33); + array.push_back(-11); + + iter = array.begin(); + ++iter; + + array.insert(iter, 99); + + TS_ASSERT_EQUALS(*iter, 99); + TS_ASSERT_EQUALS(array.size(), (unsigned int)4); + TS_ASSERT_EQUALS(array[0], 17); + TS_ASSERT_EQUALS(array[1], 99); + TS_ASSERT_EQUALS(array[2], 33); + TS_ASSERT_EQUALS(array[3], -11); + } + void test_direct_access() { Common::Array<int> array; @@ -312,3 +354,43 @@ 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 *)b)->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)); + 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_EQUALS(iter, container.end()); + } + +}; |