[Scummvm-cvs-logs] SF.net SVN: scummvm: [21509] scummvm/trunk/test/common
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Thu Mar 30 23:21:05 CEST 2006
Revision: 21509
Author: fingolfin
Date: 2006-03-30 23:20:16 -0800 (Thu, 30 Mar 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21509&view=rev
Log Message:
-----------
Some new & extended test cases
Modified Paths:
--------------
scummvm/trunk/test/common/hashmap.h
scummvm/trunk/test/common/list.h
scummvm/trunk/test/common/map.h
Modified: scummvm/trunk/test/common/hashmap.h
===================================================================
--- scummvm/trunk/test/common/hashmap.h 2006-03-31 06:42:56 UTC (rev 21508)
+++ scummvm/trunk/test/common/hashmap.h 2006-03-31 07:20:16 UTC (rev 21509)
@@ -8,36 +8,69 @@
public:
void test_empty_clear( void )
{
- Common::HashMap<int, int> map;
- TS_ASSERT( map.empty() );
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( !map.empty() );
- map.clear();
- TS_ASSERT( map.empty() );
+ Common::HashMap<int, int> container;
+ TS_ASSERT( container.empty() );
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( !container.empty() );
+ container.clear();
+ TS_ASSERT( container.empty() );
}
+
void test_contains( void )
{
- Common::HashMap<int, int> map;
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( map.contains(0) );
- TS_ASSERT( map.contains(1) );
- TS_ASSERT( !map.contains(17) );
- TS_ASSERT( !map.contains(-1) );
+ Common::HashMap<int, int> container;
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( container.contains(0) );
+ TS_ASSERT( container.contains(1) );
+ TS_ASSERT( !container.contains(17) );
+ TS_ASSERT( !container.contains(-1) );
}
void test_add_remove( void )
{
- Common::HashMap<int, int> map;
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( map.contains(1) );
- map.erase(1);
- TS_ASSERT( !map.contains(1) );
- map[1] = 42;
- TS_ASSERT( map.contains(1) );
+ Common::HashMap<int, int> container;
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( container.contains(1) );
+ container.erase(1);
+ TS_ASSERT( !container.contains(1) );
+ container[1] = 42;
+ TS_ASSERT( container.contains(1) );
}
+ void test_lookup( void )
+ {
+ Common::HashMap<int, int> container;
+ container[0] = 17;
+ container[1] = -1;
+ container[2] = 45;
+ container[3] = 12;
+ container[4] = 96;
+
+ TS_ASSERT_EQUALS( container[0], 17 );
+ TS_ASSERT_EQUALS( container[1], -1 );
+ TS_ASSERT_EQUALS( container[2], 45 );
+ TS_ASSERT_EQUALS( container[3], 12 );
+ TS_ASSERT_EQUALS( container[4], 96 );
+ }
+
+ void test_iterator_begin_end( void )
+ {
+ Common::HashMap<int, int> container;
+
+ // The container is initially empty ...
+ TS_ASSERT( container.begin() == container.end() );
+
+ // ... then non-empty ...
+ container[324] = 33;
+ TS_ASSERT( container.begin() != container.end() );
+
+ // ... and again empty.
+ container.clear();
+ TS_ASSERT( container.begin() == container.end() );
+ }
+
// TODO: Add test cases for iterators, find, ...
};
Modified: scummvm/trunk/test/common/list.h
===================================================================
--- scummvm/trunk/test/common/list.h 2006-03-31 06:42:56 UTC (rev 21508)
+++ scummvm/trunk/test/common/list.h 2006-03-31 07:20:16 UTC (rev 21509)
@@ -8,84 +8,99 @@
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() );
}
};
Modified: scummvm/trunk/test/common/map.h
===================================================================
--- scummvm/trunk/test/common/map.h 2006-03-31 06:42:56 UTC (rev 21508)
+++ scummvm/trunk/test/common/map.h 2006-03-31 07:20:16 UTC (rev 21509)
@@ -8,37 +8,54 @@
public:
void test_empty_clear( void )
{
- Common::Map<int, int> map;
- TS_ASSERT( map.empty() );
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( !map.empty() );
- map.clear();
- TS_ASSERT( map.empty() );
+ Common::Map<int, int> container;
+ TS_ASSERT( container.empty() );
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( !container.empty() );
+ container.clear();
+ TS_ASSERT( container.empty() );
}
+
void test_contains( void )
{
- Common::Map<int, int> map;
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( map.contains(0) );
- TS_ASSERT( map.contains(1) );
- TS_ASSERT( !map.contains(17) );
- TS_ASSERT( !map.contains(-1) );
+ Common::Map<int, int> container;
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( container.contains(0) );
+ TS_ASSERT( container.contains(1) );
+ TS_ASSERT( !container.contains(17) );
+ TS_ASSERT( !container.contains(-1) );
}
void test_add_remove( void )
{
- Common::Map<int, int> map;
- map[0] = 17;
- map[1] = 33;
- TS_ASSERT( map.contains(1) );
- map.erase(1);
- TS_ASSERT( !map.contains(1) );
- map[1] = 42;
- TS_ASSERT( map.contains(1) );
+ Common::Map<int, int> container;
+ container[0] = 17;
+ container[1] = 33;
+ TS_ASSERT( container.contains(1) );
+ container.erase(1);
+ TS_ASSERT( !container.contains(1) );
+ container[1] = 42;
+ TS_ASSERT( container.contains(1) );
}
+ void test_lookup( void )
+ {
+ Common::Map<int, int> container;
+ container[0] = 17;
+ container[1] = -1;
+ container[2] = 45;
+ container[3] = 12;
+ container[4] = 96;
+
+ TS_ASSERT_EQUALS( container[0], 17 );
+ TS_ASSERT_EQUALS( container[1], -1 );
+ TS_ASSERT_EQUALS( container[2], 45 );
+ TS_ASSERT_EQUALS( container[3], 12 );
+ TS_ASSERT_EQUALS( container[4], 96 );
+ }
+
void test_merge( void )
{
Common::Map<int, int> mapA, mapB;
@@ -62,5 +79,55 @@
TS_ASSERT_EQUALS( mapA[4], 96 );
}
+ void test_iterator_begin_end( void )
+ {
+ Common::Map<int, int> container;
+
+ // The container is initially empty ...
+ TS_ASSERT( container.begin() == container.end() );
+
+ // ... then non-empty ...
+ container[324] = 33;
+ TS_ASSERT( container.begin() != container.end() );
+
+ // ... and again empty.
+ container.clear();
+ TS_ASSERT( container.begin() == container.end() );
+ }
+
+ void test_iterator( void )
+ {
+ Common::Map<int, int> container;
+ Common::Map<int, int>::const_iterator iter;
+
+ // Fill the container with some random data
+ container[102] = 17;
+ container[-37] = 33;
+ container[324] = -11;
+
+ // Iterate over the container and verify that we encounter the elements
+ // in increasing order
+
+ iter = container.begin();
+
+ TS_ASSERT( iter->_key == -37 );
+ TS_ASSERT( iter->_value == 33 );
+ ++iter;
+ TS_ASSERT( iter != container.end() );
+
+ TS_ASSERT( iter->_key == 102 );
+ TS_ASSERT( iter->_value == 17 );
+ ++iter;
+ TS_ASSERT( iter != container.end() );
+
+#if 0
+ // Also test the postinc
+ TS_ASSERT( iter->_key == 324 );
+ TS_ASSERT( iter->_value == -11 );
+ iter++;
+ TS_ASSERT( iter == container.end() );
+#endif
+ }
+
// TODO: Add test cases for iterators, find, ...
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list