From 9eaa119f3134675348e1a8886a5017a7c5c7ed17 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 28 Aug 2008 09:03:43 +0000 Subject: [PATCH] Some extra HashMap tests svn-id: r34200 --- test/common/hashmap.h | 51 ++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/test/common/hashmap.h b/test/common/hashmap.h index 5aa609bc00f..acde1da028e 100644 --- a/test/common/hashmap.h +++ b/test/common/hashmap.h @@ -1,12 +1,12 @@ #include #include "common/hashmap.h" +#include "common/hash-str.h" class HashMapTestSuite : public CxxTest::TestSuite { public: - void test_empty_clear( void ) - { + void test_empty_clear(void) { Common::HashMap container; TS_ASSERT( container.empty() ); container[0] = 17; @@ -14,10 +14,17 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( !container.empty() ); container.clear(); TS_ASSERT( container.empty() ); + + Common::StringMap container2; + TS_ASSERT( container2.empty() ); + container2["foo"] = "bar"; + container2["quux"] = "blub"; + TS_ASSERT( !container2.empty() ); + container2.clear(); + TS_ASSERT( container2.empty() ); } - void test_contains( void ) - { + void test_contains(void) { Common::HashMap container; container[0] = 17; container[1] = 33; @@ -25,25 +32,41 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( container.contains(1) ); TS_ASSERT( !container.contains(17) ); TS_ASSERT( !container.contains(-1) ); + + Common::StringMap container2; + container2["foo"] = "bar"; + container2["quux"] = "blub"; + TS_ASSERT( container2.contains("foo") ); + TS_ASSERT( container2.contains("quux") ); + TS_ASSERT( !container2.contains("bar") ); + TS_ASSERT( !container2.contains("asdf") ); } - void test_add_remove( void ) - { + void test_add_remove(void) { Common::HashMap container; container[0] = 17; container[1] = 33; + container[2] = 45; + container[3] = 12; + container[4] = 96; TS_ASSERT( container.contains(1) ); container.erase(1); TS_ASSERT( !container.contains(1) ); container[1] = 42; TS_ASSERT( container.contains(1) ); container.erase(0); + TS_ASSERT( !container.empty() ); container.erase(1); + TS_ASSERT( !container.empty() ); + container.erase(2); + TS_ASSERT( !container.empty() ); + container.erase(3); + TS_ASSERT( !container.empty() ); + container.erase(4); TS_ASSERT( container.empty() ); } - void test_lookup( void ) - { + void test_lookup(void) { Common::HashMap container; container[0] = 17; container[1] = -1; @@ -58,8 +81,7 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS( container[4], 96 ); } - void test_iterator_begin_end( void ) - { + void test_iterator_begin_end(void) { Common::HashMap container; // The container is initially empty ... @@ -74,12 +96,11 @@ class HashMapTestSuite : public CxxTest::TestSuite TS_ASSERT( container.begin() == container.end() ); } - void test_hash_map_copy( void ) - { - Common::HashMap map1, map2; + void test_hash_map_copy(void) { + Common::HashMap map1, container2; map1[323] = 32; - map2 = map1; - TS_ASSERT_EQUALS(map2[323], 32); + container2 = map1; + TS_ASSERT_EQUALS(container2[323], 32); } // TODO: Add test cases for iterators, find, ...