diff options
Diffstat (limited to 'test/common/list.h')
-rw-r--r-- | test/common/list.h | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/test/common/list.h b/test/common/list.h index 41600f3f29..31ff7af399 100644 --- a/test/common/list.h +++ b/test/common/list.h @@ -8,84 +8,99 @@ class ListTestSuite : public CxxTest::TestSuite public: void test_empty_clear( void ) { - Common::List<int> list; - TS_ASSERT( list.empty() ); - list.push_back(17); - list.push_back(33); - TS_ASSERT( !list.empty() ); - list.clear(); - TS_ASSERT( list.empty() ); + Common::List<int> container; + TS_ASSERT( container.empty() ); + container.push_back(17); + container.push_back(33); + TS_ASSERT( !container.empty() ); + container.clear(); + TS_ASSERT( container.empty() ); + } + + void test_iterator_begin_end( void ) + { + Common::List<int> container; + + // The container is initially empty ... + TS_ASSERT( container.begin() == container.end() ); + + // ... then non-empty ... + container.push_back(33); + TS_ASSERT( container.begin() != container.end() ); + + // ... and again empty. + container.clear(); + TS_ASSERT( container.begin() == container.end() ); } void test_iterator( void ) { - Common::List<int> list; + Common::List<int> container; Common::List<int>::iterator iter; - // Fill the list with some random data - list.push_back(17); - list.push_back(33); - list.push_back(-11); + // Fill the container with some random data + container.push_back(17); + container.push_back(33); + container.push_back(-11); - // Iterate over the list and verify that we encounter the elements in + // Iterate over the container and verify that we encounter the elements in // the order we expect them to be. - iter = list.begin(); + iter = container.begin(); TS_ASSERT( *iter == 17 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); TS_ASSERT( *iter == 33 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); // Also test the postinc TS_ASSERT( *iter == -11 ); iter++; - TS_ASSERT( iter == list.end() ); + TS_ASSERT( iter == container.end() ); } - void test_insert( void ) { - Common::List<int> list; + Common::List<int> container; Common::List<int>::iterator iter; - // Fill the list with some random data - list.push_back(17); - list.push_back(33); - list.push_back(-11); + // Fill the container with some random data + container.push_back(17); + container.push_back(33); + container.push_back(-11); // Iterate to after the second element - iter = list.begin(); + iter = container.begin(); ++iter; ++iter; // Now insert some values here - list.insert(iter, 42); - list.insert(iter, 43); + container.insert(iter, 42); + container.insert(iter, 43); - iter = list.begin(); + iter = container.begin(); TS_ASSERT( *iter == 17 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); TS_ASSERT( *iter == 33 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); TS_ASSERT( *iter == 42 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); TS_ASSERT( *iter == 43 ); ++iter; - TS_ASSERT( iter != list.end() ); + TS_ASSERT( iter != container.end() ); TS_ASSERT( *iter == -11 ); ++iter; - TS_ASSERT( iter == list.end() ); + TS_ASSERT( iter == container.end() ); } }; |