diff options
author | Max Horn | 2009-04-27 14:25:16 +0000 |
---|---|---|
committer | Max Horn | 2009-04-27 14:25:16 +0000 |
commit | 7f20f3bb3e30c9b9cb78ea1f9033677d30c00a04 (patch) | |
tree | 3ef28e68a0c0e945f3ad8926305c9f8f2d71d616 /test | |
parent | e579f91b5c1b0949954037acf5bb4b364bfeb2b5 (diff) | |
download | scummvm-rg350-7f20f3bb3e30c9b9cb78ea1f9033677d30c00a04.tar.gz scummvm-rg350-7f20f3bb3e30c9b9cb78ea1f9033677d30c00a04.tar.bz2 scummvm-rg350-7f20f3bb3e30c9b9cb78ea1f9033677d30c00a04.zip |
COMMON: Improved efficiency of some Common::List methods; added more unit tests and some doxygen comments for Common::List and Common::Array
svn-id: r40164
Diffstat (limited to 'test')
-rw-r--r-- | test/common/list.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/common/list.h b/test/common/list.h index 67db1e1a42..3b6b9a1721 100644 --- a/test/common/list.h +++ b/test/common/list.h @@ -104,6 +104,7 @@ class ListTestSuite : public CxxTest::TestSuite container.insert(iter, 42); container.insert(iter, 43); + // Verify contents are correct iter = container.begin(); TS_ASSERT_EQUALS( *iter, 17 ); @@ -127,6 +128,82 @@ class ListTestSuite : public CxxTest::TestSuite TS_ASSERT( iter == container.end() ); } + void test_erase() { + Common::List<int> container; + Common::List<int>::iterator first, last; + + // Fill the container with some random data + container.push_back(17); + container.push_back(33); + container.push_back(-11); + container.push_back(42); + container.push_back(43); + + // Iterate to after the second element + first = container.begin(); + ++first; + ++first; + + // Iterate to after the fourth element + last = first; + ++last; + ++last; + + // Now erase that range + container.erase(first, last); + + // Verify contents are correct + Common::List<int>::iterator iter = container.begin(); + + TS_ASSERT_EQUALS( *iter, 17 ); + ++iter; + TS_ASSERT( iter != container.end() ); + + TS_ASSERT_EQUALS( *iter, 33 ); + ++iter; + TS_ASSERT( iter != container.end() ); + + TS_ASSERT_EQUALS( *iter, 43 ); + ++iter; + TS_ASSERT( iter == container.end() ); + } + + void test_remove() { + Common::List<int> container; + Common::List<int>::iterator first, last; + + // Fill the container with some random data + container.push_back(-11); + container.push_back(17); + container.push_back(33); + container.push_back(42); + container.push_back(-11); + container.push_back(42); + container.push_back(43); + + // Remove some stuff + container.remove(42); + container.remove(-11); + + // Now erase that range + container.erase(first, last); + + // Verify contents are correct + Common::List<int>::iterator iter = container.begin(); + + TS_ASSERT_EQUALS( *iter, 17 ); + ++iter; + TS_ASSERT( iter != container.end() ); + + TS_ASSERT_EQUALS( *iter, 33 ); + ++iter; + TS_ASSERT( iter != container.end() ); + + TS_ASSERT_EQUALS( *iter, 43 ); + ++iter; + TS_ASSERT( iter == container.end() ); + } + void test_reverse() { Common::List<int> container; Common::List<int>::iterator iter; @@ -186,5 +263,13 @@ class ListTestSuite : public CxxTest::TestSuite container.pop_front(); TS_ASSERT_EQUALS(container.front(), 163); TS_ASSERT_EQUALS(container.back(), 163); + + container.push_front(99); + TS_ASSERT_EQUALS(container.front(), 99); + TS_ASSERT_EQUALS(container.back(), 163); + + container.pop_back(); + TS_ASSERT_EQUALS(container.front(), 99); + TS_ASSERT_EQUALS(container.back(), 99); } }; |