1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/hash_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1192 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +//Has to be first for StackAllocator swap overload to be taken
1.20 +//into account (at least using GCC 4.0.1)
1.21 +#include "stack_allocator.h"
1.22 +
1.23 +#include <vector>
1.24 +#include <algorithm>
1.25 +#include <e32std.h>
1.26 +
1.27 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.28 +# include <hash_map>
1.29 +# include <hash_set>
1.30 +# include <rope>
1.31 +# endif
1.32 +
1.33 +#include <string>
1.34 +
1.35 +#include "cppunit/cppunit_proxy.h"
1.36 +
1.37 +#if defined (__MVS__)
1.38 +const char star = 92;
1.39 +#else
1.40 +const char star = 42;
1.41 +#endif
1.42 +
1.43 +#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
1.44 +using namespace std;
1.45 +#endif
1.46 +
1.47 +//
1.48 +// TestCase class
1.49 +//
1.50 +class HashTest : public CPPUNIT_NS::TestCase
1.51 +{
1.52 + CPPUNIT_TEST_SUITE(HashTest);
1.53 +#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
1.54 + CPPUNIT_IGNORE;
1.55 +#endif
1.56 + CPPUNIT_TEST(hmap1);
1.57 + CPPUNIT_TEST(hmmap1);
1.58 + CPPUNIT_TEST(hmset1);
1.59 + CPPUNIT_TEST(hset2);
1.60 + CPPUNIT_TEST(insert_erase);
1.61 + CPPUNIT_TEST(allocator_with_state);
1.62 + CPPUNIT_TEST(hash_map_cov1);
1.63 + CPPUNIT_TEST(hash_map_cov2);
1.64 + CPPUNIT_TEST(hash_map_cov3);
1.65 + CPPUNIT_TEST(hash_map_cov4);
1.66 + CPPUNIT_TEST(hash_map_cov5);
1.67 + CPPUNIT_TEST(hash_map_cov6);
1.68 + CPPUNIT_TEST(hash_multimap_cov1);
1.69 + CPPUNIT_TEST(hash_multimap_cov2);
1.70 + CPPUNIT_TEST(hash_multimap_cov3);
1.71 + CPPUNIT_TEST(hash_set_cov1);
1.72 + CPPUNIT_TEST(hash_set_cov2);
1.73 + CPPUNIT_TEST(hash_set_cov3);
1.74 + CPPUNIT_TEST(hash_set_cov4);
1.75 + CPPUNIT_TEST(hash_set_cov5);
1.76 + CPPUNIT_TEST(hash_set_cov6);
1.77 + CPPUNIT_TEST(hash_multiset_cov1);
1.78 + CPPUNIT_TEST(hash_multiset_cov2);
1.79 + CPPUNIT_TEST(hash_multiset_cov3);
1.80 + //CPPUNIT_TEST(equality);
1.81 + CPPUNIT_TEST_SUITE_END();
1.82 +
1.83 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.84 + typedef hash_multiset<char, hash<char>, equal_to<char> > hmset;
1.85 +#endif
1.86 +
1.87 +protected:
1.88 + void hmap1();
1.89 + void hmmap1();
1.90 + void hmset1();
1.91 + void hset2();
1.92 + void insert_erase();
1.93 + void hash_map_cov1();
1.94 + void hash_map_cov2();
1.95 + void hash_map_cov3();
1.96 + void hash_map_cov4();
1.97 + void hash_map_cov5();
1.98 + void hash_map_cov6();
1.99 + void hash_multimap_cov1();
1.100 + void hash_multimap_cov2();
1.101 + void hash_multimap_cov3();
1.102 + void hash_set_cov1();
1.103 + void hash_set_cov2();
1.104 + void hash_set_cov3();
1.105 + void hash_set_cov4();
1.106 + void hash_set_cov5();
1.107 + void hash_set_cov6();
1.108 + void hash_multiset_cov1();
1.109 + void hash_multiset_cov2();
1.110 + void hash_multiset_cov3();
1.111 + //void equality();
1.112 + void allocator_with_state();
1.113 +};
1.114 +
1.115 +CPPUNIT_TEST_SUITE_REGISTRATION(HashTest);
1.116 +
1.117 +//
1.118 +// tests implementation
1.119 +//
1.120 +void HashTest::hmap1()
1.121 +{
1.122 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.123 + typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
1.124 + maptype m;
1.125 + // Store mappings between roman numerals and decimals.
1.126 + m['l'] = "50";
1.127 + m['x'] = "20"; // Deliberate mistake.
1.128 + m['v'] = "5";
1.129 + m['i'] = "1";
1.130 + CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"20") );
1.131 + m['x'] = "10"; // Correct mistake.
1.132 + CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"10") );
1.133 +
1.134 + CPPUNIT_ASSERT( !strcmp(m['z'].c_str(),"") );
1.135 +
1.136 + CPPUNIT_ASSERT( m.count('z')==1 );
1.137 + pair<maptype::iterator, bool> p = m.insert(pair<const char, crope>('c', crope("100")));
1.138 +
1.139 + CPPUNIT_ASSERT(p.second);
1.140 +
1.141 + p = m.insert(pair<const char, crope>('c', crope("100")));
1.142 + CPPUNIT_ASSERT(!p.second);
1.143 +
1.144 + //Some iterators compare check, really compile time checks
1.145 + maptype::iterator ite(m.begin());
1.146 + maptype::const_iterator cite(m.begin());
1.147 + cite = m.begin();
1.148 + maptype const& cm = m;
1.149 + cite = cm.begin();
1.150 + CPPUNIT_ASSERT( ite == cite );
1.151 + CPPUNIT_ASSERT( !(ite != cite) );
1.152 + CPPUNIT_ASSERT( cite == ite );
1.153 + CPPUNIT_ASSERT( !(cite != ite) );
1.154 +#endif
1.155 +}
1.156 +
1.157 +void HashTest::hmmap1()
1.158 +{
1.159 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.160 + typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap;
1.161 + mmap m;
1.162 + CPPUNIT_ASSERT(m.count('X')==0);
1.163 + m.insert(pair<const char,int>('X', 10)); // Standard way.
1.164 + CPPUNIT_ASSERT(m.count('X')==1);
1.165 +// m.insert('X', 20); // Non-standard, but very convenient!
1.166 + m.insert(pair<const char,int>('X', 20)); // jbuck: standard way
1.167 + CPPUNIT_ASSERT(m.count('X')==2);
1.168 +// m.insert('Y', 32);
1.169 + m.insert(pair<const char,int>('Y', 32)); // jbuck: standard way
1.170 + mmap::iterator i = m.find('X'); // Find first match.
1.171 +
1.172 + CPPUNIT_ASSERT((*i).first=='X');
1.173 + CPPUNIT_ASSERT((*i).second==10);
1.174 + i++;
1.175 + CPPUNIT_ASSERT((*i).first=='X');
1.176 + CPPUNIT_ASSERT((*i).second==20);
1.177 + i++;
1.178 + CPPUNIT_ASSERT((*i).first=='Y');
1.179 + CPPUNIT_ASSERT((*i).second==32);
1.180 + i++;
1.181 + CPPUNIT_ASSERT(i==m.end());
1.182 +
1.183 + size_t count = m.erase('X');
1.184 + CPPUNIT_ASSERT(count==2);
1.185 +
1.186 + //Some iterators compare check, really compile time checks
1.187 + mmap::iterator ite(m.begin());
1.188 + mmap::const_iterator cite(m.begin());
1.189 + CPPUNIT_ASSERT( ite == cite );
1.190 + CPPUNIT_ASSERT( !(ite != cite) );
1.191 + CPPUNIT_ASSERT( cite == ite );
1.192 + CPPUNIT_ASSERT( !(cite != ite) );
1.193 +
1.194 + typedef hash_multimap<size_t, size_t> HMapType;
1.195 + HMapType hmap;
1.196 +
1.197 + //We fill the map to implicitely start a rehash.
1.198 + for (size_t counter = 0; counter < 3077; ++counter)
1.199 + hmap.insert(HMapType::value_type(1, counter));
1.200 +
1.201 + hmap.insert(HMapType::value_type(12325, 1));
1.202 + hmap.insert(HMapType::value_type(12325, 2));
1.203 +
1.204 + CPPUNIT_ASSERT( hmap.count(12325) == 2 );
1.205 +
1.206 + //At this point 23 goes to the same bucket as 12325, it used to reveal a bug.
1.207 + hmap.insert(HMapType::value_type(23, 0));
1.208 +
1.209 + CPPUNIT_ASSERT( hmap.count(12325) == 2 );
1.210 +#endif
1.211 +}
1.212 +
1.213 +void HashTest::hmset1()
1.214 +{
1.215 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.216 + hmset s;
1.217 + CPPUNIT_ASSERT( s.count(star) == 0 );
1.218 + s.insert(star);
1.219 + CPPUNIT_ASSERT( s.count(star) == 1 );
1.220 + s.insert(star);
1.221 + CPPUNIT_ASSERT( s.count(star) == 2 );
1.222 + hmset::iterator i = s.find(char(40));
1.223 + CPPUNIT_ASSERT( i == s.end() );
1.224 +
1.225 + i = s.find(star);
1.226 + CPPUNIT_ASSERT( i != s.end() )
1.227 + CPPUNIT_ASSERT( *i == '*' );
1.228 + CPPUNIT_ASSERT( s.erase(star) == 2 );
1.229 +#endif
1.230 +}
1.231 +void HashTest::hset2()
1.232 +{
1.233 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.234 + hash_set<int, hash<int>, equal_to<int> > s;
1.235 + pair<hash_set<int, hash<int>, equal_to<int> >::iterator, bool> p = s.insert(42);
1.236 + CPPUNIT_ASSERT( p.second );
1.237 + CPPUNIT_ASSERT( *(p.first) == 42 );
1.238 +
1.239 + p = s.insert(42);
1.240 + CPPUNIT_ASSERT( !p.second );
1.241 +#endif
1.242 +}
1.243 +
1.244 +void HashTest::insert_erase()
1.245 +{
1.246 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.247 + typedef hash_map<string, size_t, hash<string>, equal_to<string> > hmap;
1.248 + typedef hmap::value_type val_type;
1.249 + {
1.250 + hmap values;
1.251 + CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
1.252 + CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
1.253 + CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
1.254 +
1.255 + CPPUNIT_ASSERT( values.erase("foo") == 1 );
1.256 + CPPUNIT_ASSERT( values.erase("bar") == 1 );
1.257 + CPPUNIT_ASSERT( values.erase("abc") == 1 );
1.258 + }
1.259 +
1.260 + {
1.261 + hmap values;
1.262 + CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
1.263 + CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
1.264 + CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
1.265 +
1.266 + CPPUNIT_ASSERT( values.erase("abc") == 1 );
1.267 + CPPUNIT_ASSERT( values.erase("bar") == 1 );
1.268 + CPPUNIT_ASSERT( values.erase("foo") == 1 );
1.269 + }
1.270 +#endif
1.271 +}
1.272 +
1.273 +/*
1.274 + * Here is the test showing why equality operator on hash containers
1.275 + * has no meaning:
1.276 +
1.277 +struct equality_hash_func {
1.278 + size_t operator () (size_t val) const {
1.279 + return val % 10;
1.280 + }
1.281 +};
1.282 +
1.283 +void HashTest::equality()
1.284 +{
1.285 + hash_set<size_t, equality_hash_func, equal_to<size_t> > s1, s2;
1.286 +
1.287 + s1.insert(10);
1.288 + s1.insert(20);
1.289 +
1.290 + s2.insert(20);
1.291 + s2.insert(10);
1.292 +
1.293 + //s1 and s2 contains both 10 and 20:
1.294 + CPPUNIT_ASSERT( s1 == s2 );
1.295 +}
1.296 +*/
1.297 +
1.298 +void HashTest::allocator_with_state()
1.299 +{
1.300 +#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
1.301 + char buf1[2048];
1.302 + StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
1.303 +
1.304 + char buf2[2048];
1.305 + StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
1.306 +
1.307 + {
1.308 + typedef hash_set<int, hash<int>, equal_to<int>, StackAllocator<int> > HashSetInt;
1.309 + HashSetInt hint1(10, hash<int>(), equal_to<int>(), stack1);
1.310 +
1.311 + int i;
1.312 + for (i = 0; i < 5; ++i)
1.313 + hint1.insert(i);
1.314 + HashSetInt hint1Cpy(hint1);
1.315 +
1.316 + HashSetInt hint2(10, hash<int>(), equal_to<int>(), stack2);
1.317 + for (; i < 10; ++i)
1.318 + hint2.insert(i);
1.319 + HashSetInt hint2Cpy(hint2);
1.320 +
1.321 + hint1.swap(hint2);
1.322 +
1.323 + CPPUNIT_ASSERT( hint1.get_allocator().swaped() );
1.324 + CPPUNIT_ASSERT( hint2.get_allocator().swaped() );
1.325 +
1.326 + CPPUNIT_ASSERT( hint1.get_allocator() == stack2 );
1.327 + CPPUNIT_ASSERT( hint2.get_allocator() == stack1 );
1.328 + }
1.329 + CPPUNIT_ASSERT( stack1.ok() );
1.330 + CPPUNIT_ASSERT( stack2.ok() );
1.331 +#endif
1.332 +}
1.333 +void HashTest::hash_map_cov1()
1.334 + {
1.335 + __UHEAP_MARK;
1.336 + {
1.337 + hash_map <int, int> hm1, hm2;
1.338 + hash_map <int, int>::iterator hm1_Iter;
1.339 + hash_map <int, int>::const_iterator hm1_cIter;
1.340 + typedef pair <int, int> Int_Pair;
1.341 +
1.342 + hm1.insert ( Int_Pair ( 1, 10 ) );
1.343 + hm1.insert ( Int_Pair ( 2, 20 ) );
1.344 + hm1.insert ( Int_Pair ( 3, 30 ) );
1.345 + hm2.insert ( Int_Pair ( 30, 300 ) );
1.346 +
1.347 + hm1.swap( hm2 );
1.348 + hm1_Iter = hm1.begin( );
1.349 + CPPUNIT_ASSERT( hm1_Iter -> second == 300);
1.350 + hm1_Iter = hm1.end( );
1.351 +
1.352 + hm1_cIter = hm1.end( );
1.353 + hm1.clear();
1.354 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.355 + CPPUNIT_ASSERT( hm1.empty() == true );
1.356 + }
1.357 + {
1.358 + hash_map <int, int> hm1, hm2;
1.359 + hash_map <int, int>::iterator hm1_Iter;
1.360 + hash_map <int, int>::const_iterator hm1_cIter;
1.361 + typedef pair <int, int> Int_Pair;
1.362 +
1.363 + hm1.insert ( Int_Pair ( 1, 10 ) );
1.364 + hm1.insert ( Int_Pair ( 2, 20 ) );
1.365 + hm1.insert ( Int_Pair ( 3, 30 ) );
1.366 + hm2.insert ( Int_Pair ( 30, 300 ) );
1.367 +
1.368 + swap( hm1,hm2 );
1.369 + hm1_Iter = hm1.begin( );
1.370 + CPPUNIT_ASSERT( hm1_Iter -> second == 300);
1.371 + hm1_Iter = hm1.end( );
1.372 +
1.373 + hm1_cIter = hm1.end( );
1.374 + hm1.clear();
1.375 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.376 + CPPUNIT_ASSERT( hm1.empty() == true );
1.377 + }
1.378 + __UHEAP_MARKEND;
1.379 + }
1.380 +void HashTest::hash_map_cov2()
1.381 + {
1.382 + __UHEAP_MARK;
1.383 + {
1.384 + hash_map <int, int> hm1;
1.385 + int i,bcount;
1.386 + typedef pair <int, int> Int_Pair;
1.387 +
1.388 + hm1.insert ( Int_Pair ( 1, 1 ) );
1.389 + i = hm1.size( );
1.390 + CPPUNIT_ASSERT( i == 1);
1.391 +
1.392 + i = hm1.max_size(); // for covering the api
1.393 +
1.394 + hm1.insert ( Int_Pair ( 2, 4 ) );
1.395 + i = hm1.size( );
1.396 + CPPUNIT_ASSERT( i == 2);
1.397 + hm1.resize(10);
1.398 + bcount = hm1.bucket_count();
1.399 + CPPUNIT_ASSERT( bcount >= 10);
1.400 + hm1.elems_in_bucket(1);
1.401 + }
1.402 + {
1.403 + typedef hash_multimap<int, int> mmap;
1.404 + mmap m;
1.405 +
1.406 + typedef pair <int, int> Int_Pair;
1.407 + m.insert ( Int_Pair ( 1, 10 ) );
1.408 + m.insert ( Int_Pair ( 2, 20 ) );
1.409 + m.insert ( Int_Pair ( 3, 30 ) );
1.410 +
1.411 + std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
1.412 + CPPUNIT_ASSERT( pair1.first->first == 2);
1.413 + CPPUNIT_ASSERT( pair1.first->second == 20);
1.414 + std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
1.415 + CPPUNIT_ASSERT( pair2.first->first == 1);
1.416 + CPPUNIT_ASSERT( pair2.first->second == 10);
1.417 + }
1.418 + {
1.419 + typedef hash_multimap<int, int> mmap;
1.420 + mmap m;
1.421 +
1.422 + typedef pair <int, int> Int_Pair;
1.423 + m.insert ( Int_Pair ( 1, 10 ) );
1.424 + m.insert ( Int_Pair ( 2, 20 ) );
1.425 + m.insert ( Int_Pair ( 3, 30 ) );
1.426 +
1.427 + m.erase(m.begin());
1.428 + mmap::iterator i1 = m.begin();
1.429 + CPPUNIT_ASSERT( i1 -> second == 20);
1.430 + CPPUNIT_ASSERT( m.size() == 2 );
1.431 + m.erase(m.begin(),m.end());
1.432 + CPPUNIT_ASSERT( m.size() == 0 );
1.433 + }
1.434 + __UHEAP_MARKEND;
1.435 + }
1.436 +void HashTest::hash_map_cov3()
1.437 + {
1.438 + __UHEAP_MARK;
1.439 + {
1.440 + typedef hash_multimap<int, int> mmap;
1.441 + mmap m;
1.442 +
1.443 + typedef pair <int, int> Int_Pair;
1.444 + m.insert ( Int_Pair ( 1, 10 ) );
1.445 + m.insert ( Int_Pair ( 2, 20 ) );
1.446 + m.insert ( Int_Pair ( 3, 30 ) );
1.447 +
1.448 + mmap::iterator i1 = m.find(1);
1.449 + CPPUNIT_ASSERT( i1 -> second == 10);
1.450 + mmap::const_iterator i2 = m.find(3);
1.451 + CPPUNIT_ASSERT( i2 -> second == 30);
1.452 +
1.453 + // negative test case where the element to find is not present in the
1.454 + // hash , so it returns the successive element of the last element.
1.455 + mmap::iterator i3 = m.find(4);
1.456 + mmap::iterator i4 = m.end();
1.457 + CPPUNIT_ASSERT( i3 == i4);
1.458 + }
1.459 + {
1.460 + typedef hash_multimap<int, int> mmap;
1.461 + typedef allocator<std::pair<int, int> > Myalloc;
1.462 + mmap m;
1.463 +
1.464 + mmap::allocator_type al = m.get_allocator();
1.465 + CPPUNIT_ASSERT ((al == Myalloc()) == true);
1.466 +
1.467 + mmap::hasher hfn = m.hash_funct(); // returns the hasher function
1.468 + }
1.469 + {
1.470 + typedef hash_multimap<int, int> mmap;
1.471 + mmap m1,m2;
1.472 +
1.473 + typedef pair <int, int> Int_Pair;
1.474 + m1.insert ( Int_Pair ( 1, 10 ) );
1.475 + m1.insert ( Int_Pair ( 2, 20 ) );
1.476 + m1.insert ( Int_Pair ( 3, 30 ) );
1.477 +
1.478 + m2.insert ( m1.begin(),m1.end());
1.479 + mmap::iterator i1 = m2.begin();
1.480 + CPPUNIT_ASSERT( i1 -> second == 10);
1.481 + }
1.482 + __UHEAP_MARKEND;
1.483 + }
1.484 +void HashTest::hash_map_cov4()
1.485 + {
1.486 + __UHEAP_MARK;
1.487 + {
1.488 + typedef hash_map<int, int> mmap;
1.489 + mmap m;
1.490 + typedef pair <int, int> Int_Pair;
1.491 + m.insert ( Int_Pair ( 1, 10 ) );
1.492 + m.insert ( Int_Pair ( 2, 20 ) );
1.493 + m.insert ( Int_Pair ( 3, 30 ) );
1.494 +
1.495 + std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
1.496 + CPPUNIT_ASSERT( pair1.first->first == 2);
1.497 + CPPUNIT_ASSERT( pair1.first->second == 20);
1.498 + std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
1.499 + CPPUNIT_ASSERT( pair2.first->first == 1);
1.500 + CPPUNIT_ASSERT( pair2.first->second == 10);
1.501 + }
1.502 + {
1.503 + typedef hash_map<int, int> mmap;
1.504 + mmap m;
1.505 + typedef pair <int, int> Int_Pair;
1.506 + m.insert ( Int_Pair ( 1, 10 ) );
1.507 + m.insert ( Int_Pair ( 2, 20 ) );
1.508 + m.insert ( Int_Pair ( 3, 30 ) );
1.509 +
1.510 + m.erase(m.begin());
1.511 + mmap::iterator i1 = m.begin();
1.512 + CPPUNIT_ASSERT( i1 -> second == 20);
1.513 + CPPUNIT_ASSERT( m.size() == 2 );
1.514 + m.erase(m.begin(),m.end());
1.515 + CPPUNIT_ASSERT( m.size() == 0 );
1.516 + }
1.517 + {
1.518 + typedef hash_map<int, int> mmap;
1.519 + mmap m;
1.520 +
1.521 + typedef pair <int, int> Int_Pair;
1.522 + m.insert ( Int_Pair ( 1, 10 ) );
1.523 + m.insert ( Int_Pair ( 2, 20 ) );
1.524 + m.insert ( Int_Pair ( 3, 30 ) );
1.525 +
1.526 + mmap::iterator i1 = m.find(1);
1.527 + CPPUNIT_ASSERT( i1 -> second == 10);
1.528 + mmap::const_iterator i2 = m.find(3);
1.529 + CPPUNIT_ASSERT( i2 -> second == 30);
1.530 + }
1.531 + __UHEAP_MARKEND;
1.532 + }
1.533 +void HashTest::hash_map_cov5()
1.534 + {
1.535 + __UHEAP_MARK;
1.536 + {
1.537 + typedef hash_map<int, int> mmap;
1.538 + typedef allocator<std::pair<int, int> > Myalloc;
1.539 + mmap m;
1.540 + mmap::allocator_type al = m.get_allocator();
1.541 + CPPUNIT_ASSERT ((al == Myalloc()) == true);
1.542 +
1.543 + mmap::hasher hfn = m.hash_funct(); // returns the hasher function
1.544 + }
1.545 + {
1.546 + typedef hash_map<int, int> mmap;
1.547 + mmap m1,m2;
1.548 +
1.549 + typedef pair <int, int> Int_Pair;
1.550 + m1.insert ( Int_Pair ( 1, 10 ) );
1.551 + m1.insert ( Int_Pair ( 2, 20 ) );
1.552 + m1.insert ( Int_Pair ( 3, 30 ) );
1.553 +
1.554 + m2.insert ( m1.begin(),m1.end());
1.555 + mmap::iterator i1 = m2.begin();
1.556 + CPPUNIT_ASSERT( i1 -> second == 10);
1.557 + }
1.558 + {
1.559 + typedef hash_map<char, int> mmap;
1.560 + mmap c1;
1.561 + mmap::key_equal cmpfn = c1.key_eq();
1.562 + CPPUNIT_ASSERT( cmpfn('a','a') == true);
1.563 +
1.564 + c1.max_bucket_count(); // for covering the api
1.565 + }
1.566 + {
1.567 + typedef hash_map<int, int> mmap;
1.568 + mmap m1;
1.569 + typedef pair <int, int> Int_Pair;
1.570 + m1.insert_noresize ( Int_Pair ( 1, 10 ) );
1.571 + m1.insert_noresize ( Int_Pair ( 2, 20 ) );
1.572 + m1.insert_noresize ( Int_Pair ( 3, 30 ) );
1.573 +
1.574 + mmap::iterator i1 = m1.begin();
1.575 + CPPUNIT_ASSERT( i1 -> second == 10);
1.576 + }
1.577 + __UHEAP_MARKEND;
1.578 + }
1.579 +void HashTest::hash_map_cov6()
1.580 + {
1.581 + __UHEAP_MARK;
1.582 + {
1.583 + typedef hash_map<int, int> mmap;
1.584 + mmap m1;
1.585 + int bcount;
1.586 +
1.587 + typedef pair <int, int> Int_Pair;
1.588 + m1.insert ( Int_Pair ( 1, 10 ) );
1.589 + m1.insert ( Int_Pair ( 2, 20 ) );
1.590 + m1.insert ( Int_Pair ( 3, 30 ) );
1.591 +
1.592 + mmap m2(m1);
1.593 + mmap::iterator i1 = m2.begin();
1.594 + CPPUNIT_ASSERT( i1 -> second == 10);
1.595 +
1.596 + mmap m3(10);
1.597 + bcount = m3.bucket_count();
1.598 + CPPUNIT_ASSERT( bcount >= 10);
1.599 +
1.600 + mmap::hasher hfn = m1.hash_funct();
1.601 + mmap m4(20,hfn);
1.602 + bcount = m4.bucket_count();
1.603 + CPPUNIT_ASSERT( bcount >= 20);
1.604 +
1.605 + mmap m5(m1.begin(),m2.end());
1.606 + CPPUNIT_ASSERT( m5.size() == 3);
1.607 +
1.608 + mmap m6(m1.begin(),m2.end(),30);
1.609 + CPPUNIT_ASSERT( m6.size() == 3);
1.610 + bcount = m6.bucket_count();
1.611 + CPPUNIT_ASSERT( bcount >= 30);
1.612 +
1.613 + mmap m7(m1.begin(),m2.end(),30,hfn);
1.614 + CPPUNIT_ASSERT( m7.size() == 3);
1.615 + bcount = m7.bucket_count();
1.616 + CPPUNIT_ASSERT( bcount >= 30);
1.617 +
1.618 + mmap::key_equal cmpfn;// = c1.key_eq();
1.619 + mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1.620 +
1.621 + mmap m9(30,hfn,cmpfn);
1.622 + }
1.623 + __UHEAP_MARKEND;
1.624 + }
1.625 +
1.626 +void HashTest::hash_multimap_cov1()
1.627 + {
1.628 + __UHEAP_MARK;
1.629 + {
1.630 + hash_multimap <int, int> hm1, hm2;
1.631 + hash_multimap <int, int>::iterator hm1_Iter;
1.632 + hash_multimap <int, int>::const_iterator hm1_cIter;
1.633 + typedef pair <int, int> Int_Pair;
1.634 +
1.635 + hm1.insert ( Int_Pair ( 1, 10 ) );
1.636 + hm1.insert ( Int_Pair ( 2, 20 ) );
1.637 + hm1.insert ( Int_Pair ( 3, 30 ) );
1.638 + hm2.insert ( Int_Pair ( 30, 300 ) );
1.639 +
1.640 + hm1.swap( hm2 );
1.641 + hm1_Iter = hm1.begin( );
1.642 + CPPUNIT_ASSERT( hm1_Iter -> second == 300);
1.643 + hm1_Iter = hm1.end( );
1.644 + hm1_cIter = hm1.end( );
1.645 + hm1.clear();
1.646 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.647 + CPPUNIT_ASSERT( hm1.empty() == true );
1.648 + }
1.649 + {
1.650 + hash_multimap <int, int> hm1, hm2;
1.651 + hash_multimap <int, int>::iterator hm1_Iter;
1.652 + hash_multimap <int, int>::const_iterator hm1_cIter;
1.653 + typedef pair <int, int> Int_Pair;
1.654 +
1.655 + hm1.insert ( Int_Pair ( 1, 10 ) );
1.656 + hm1.insert ( Int_Pair ( 2, 20 ) );
1.657 + hm1.insert ( Int_Pair ( 3, 30 ) );
1.658 + hm2.insert ( Int_Pair ( 30, 300 ) );
1.659 +
1.660 + swap( hm1,hm2 );
1.661 + hm1_Iter = hm1.begin( );
1.662 + CPPUNIT_ASSERT( hm1_Iter -> second == 300);
1.663 + hm1_Iter = hm1.end( );
1.664 + hm1_cIter = hm1.end( );
1.665 + hm1.clear();
1.666 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.667 + CPPUNIT_ASSERT( hm1.empty() == true );
1.668 + }
1.669 + __UHEAP_MARKEND;
1.670 + }
1.671 +void HashTest::hash_multimap_cov2()
1.672 + {
1.673 + __UHEAP_MARK;
1.674 + {
1.675 + hash_multimap <int, int> hm1;
1.676 + int i,bcount;
1.677 + typedef pair <int, int> Int_Pair;
1.678 +
1.679 + hm1.insert ( Int_Pair ( 1, 1 ) );
1.680 + i = hm1.size( );
1.681 + CPPUNIT_ASSERT( i == 1);
1.682 +
1.683 + i = hm1.max_size(); // for covering the api
1.684 +
1.685 + hm1.insert ( Int_Pair ( 2, 4 ) );
1.686 + i = hm1.size( );
1.687 + CPPUNIT_ASSERT( i == 2);
1.688 + hm1.resize(10);
1.689 + bcount = hm1.bucket_count();
1.690 + CPPUNIT_ASSERT( bcount >= 10);
1.691 + hm1.elems_in_bucket(1);
1.692 + }
1.693 + {
1.694 + typedef hash_multimap<int, int> mmap;
1.695 + mmap m1;
1.696 +
1.697 + typedef pair <int, int> Int_Pair;
1.698 + m1.insert_noresize ( Int_Pair ( 1, 10 ) );
1.699 + m1.insert_noresize ( Int_Pair ( 2, 20 ) );
1.700 + m1.insert_noresize ( Int_Pair ( 3, 30 ) );
1.701 +
1.702 + mmap::iterator i1 = m1.begin();
1.703 + CPPUNIT_ASSERT( i1 -> second == 10);
1.704 + }
1.705 + {
1.706 + typedef hash_multimap<char, int> mmap;
1.707 + mmap c1;
1.708 + mmap::key_equal cmpfn = c1.key_eq();
1.709 + CPPUNIT_ASSERT( cmpfn('a','a') == true);
1.710 +
1.711 + c1.max_bucket_count(); // for covering the api
1.712 + }
1.713 + __UHEAP_MARKEND;
1.714 + }
1.715 +void HashTest::hash_multimap_cov3()
1.716 + {
1.717 + __UHEAP_MARK;
1.718 + {
1.719 + typedef hash_multimap<int, int> mmap;
1.720 + mmap m1;
1.721 + int bcount;
1.722 +
1.723 + typedef pair <int, int> Int_Pair;
1.724 + m1.insert ( Int_Pair ( 1, 10 ) );
1.725 + m1.insert ( Int_Pair ( 2, 20 ) );
1.726 + m1.insert ( Int_Pair ( 3, 30 ) );
1.727 +
1.728 + mmap m2(m1);
1.729 + mmap::iterator i1 = m2.begin();
1.730 + CPPUNIT_ASSERT( i1 -> second == 10);
1.731 +
1.732 + mmap m3(10);
1.733 + bcount = m3.bucket_count();
1.734 + CPPUNIT_ASSERT( bcount >= 10);
1.735 +
1.736 + mmap::hasher hfn = m1.hash_funct();
1.737 + mmap m4(20,hfn);
1.738 + bcount = m4.bucket_count();
1.739 + CPPUNIT_ASSERT( bcount >= 20);
1.740 +
1.741 + mmap m5(m1.begin(),m2.end());
1.742 + CPPUNIT_ASSERT( m5.size() == 3);
1.743 +
1.744 + mmap m6(m1.begin(),m2.end(),30);
1.745 + CPPUNIT_ASSERT( m6.size() == 3);
1.746 + bcount = m6.bucket_count();
1.747 + CPPUNIT_ASSERT( bcount >= 30);
1.748 +
1.749 + mmap m7(m1.begin(),m2.end(),30,hfn);
1.750 + CPPUNIT_ASSERT( m7.size() == 3);
1.751 + bcount = m7.bucket_count();
1.752 + CPPUNIT_ASSERT( bcount >= 30);
1.753 +
1.754 + mmap::key_equal cmpfn;
1.755 + mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1.756 +
1.757 + mmap m9(30,hfn,cmpfn);
1.758 + }
1.759 + __UHEAP_MARKEND;
1.760 + }
1.761 +
1.762 +void HashTest::hash_set_cov1()
1.763 + {
1.764 + __UHEAP_MARK;
1.765 + {
1.766 + hash_set <int> hm1, hm2;
1.767 + hash_set <int>::iterator hm1_Iter;
1.768 + hash_set <int>::const_iterator hm1_cIter;
1.769 +
1.770 + hm1.insert ( 10 );
1.771 + hm1.insert ( 20 );
1.772 + hm1.insert ( 30 );
1.773 + hm2.insert ( 300 );
1.774 +
1.775 + hm1.swap( hm2 );
1.776 + hm1_Iter = hm1.begin( );
1.777 + CPPUNIT_ASSERT( *hm1_Iter == 300);
1.778 + hm1_Iter = hm1.end( );
1.779 + hm1_cIter = hm1.end( );
1.780 + hm1.clear();
1.781 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.782 + CPPUNIT_ASSERT( hm1.empty() == true );
1.783 + }
1.784 + {
1.785 + hash_set <int> hm1, hm2;
1.786 + hash_set <int>::iterator hm1_Iter;
1.787 + hash_set <int>::const_iterator hm1_cIter;
1.788 +
1.789 + hm1.insert ( 10 );
1.790 + hm1.insert ( 20 );
1.791 + hm1.insert ( 30 );
1.792 + hm2.insert ( 300 );
1.793 +
1.794 + swap( hm1,hm2 );
1.795 + hm1_Iter = hm1.begin( );
1.796 + CPPUNIT_ASSERT( *hm1_Iter == 300);
1.797 + hm1_Iter = hm1.end( );
1.798 + hm1_cIter = hm1.end( );
1.799 + hm1.clear();
1.800 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.801 + CPPUNIT_ASSERT( hm1.empty() == true );
1.802 + }
1.803 + __UHEAP_MARKEND;
1.804 + }
1.805 +void HashTest::hash_set_cov2()
1.806 + {
1.807 + __UHEAP_MARK;
1.808 + {
1.809 + hash_set <int> hm1;
1.810 + int i,bcount;
1.811 +
1.812 + hm1.insert ( 1 );
1.813 + i = hm1.size( );
1.814 + CPPUNIT_ASSERT( i == 1);
1.815 +
1.816 + i = hm1.max_size(); // for covering the api
1.817 +
1.818 + hm1.insert ( 4 );
1.819 + i = hm1.size( );
1.820 + CPPUNIT_ASSERT( i == 2);
1.821 + hm1.resize(10);
1.822 + bcount = hm1.bucket_count();
1.823 + CPPUNIT_ASSERT( bcount >= 10);
1.824 + hm1.elems_in_bucket(1);
1.825 + }
1.826 + {
1.827 + typedef hash_multiset<int> mmap;
1.828 + mmap m;
1.829 +
1.830 + m.insert ( 10 );
1.831 + m.insert ( 20 );
1.832 + m.insert ( 30 );
1.833 +
1.834 + std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
1.835 + CPPUNIT_ASSERT( *(pair1.first) == 20);
1.836 + CPPUNIT_ASSERT( *(pair1.second) == 30);
1.837 + // negative test case for equal_range where the key value is not present.
1.838 + std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
1.839 + CPPUNIT_ASSERT( pair2.first == m.end());
1.840 + CPPUNIT_ASSERT( pair2.second == m.end());
1.841 + }
1.842 + {
1.843 + typedef hash_multiset<int> mmap;
1.844 + mmap m;
1.845 +
1.846 + m.insert ( 10 );
1.847 + m.insert ( 20 );
1.848 + m.insert ( 30 );
1.849 +
1.850 + m.erase(m.begin());
1.851 + mmap::iterator i1 = m.begin();
1.852 + CPPUNIT_ASSERT( *i1 == 20);
1.853 + CPPUNIT_ASSERT( m.size() == 2 );
1.854 + m.erase(m.begin(),m.end());
1.855 + CPPUNIT_ASSERT( m.size() == 0 );
1.856 + }
1.857 + __UHEAP_MARKEND;
1.858 + }
1.859 +void HashTest::hash_set_cov3()
1.860 + {
1.861 + __UHEAP_MARK;
1.862 + {
1.863 + typedef hash_multiset<int> mmap;
1.864 + mmap m;
1.865 +
1.866 + m.insert ( 10 );
1.867 + m.insert ( 20 );
1.868 + m.insert ( 30 );
1.869 +
1.870 + mmap::iterator i1 = m.find(10);
1.871 + CPPUNIT_ASSERT( *i1 == 10);
1.872 + mmap::const_iterator i2 = m.find(30);
1.873 + CPPUNIT_ASSERT( *i2 == 30);
1.874 + }
1.875 + {
1.876 + typedef hash_multiset<int> mmap;
1.877 + typedef allocator<std::pair<int, int> > Myalloc;
1.878 + mmap m;
1.879 +
1.880 + mmap::allocator_type al = m.get_allocator();
1.881 + CPPUNIT_ASSERT ((al == Myalloc()) == true);
1.882 +
1.883 + mmap::hasher hfn = m.hash_funct(); // returns the hasher function
1.884 + }
1.885 + {
1.886 + typedef hash_multiset<int> mmap;
1.887 + mmap m1,m2;
1.888 +
1.889 + m1.insert ( 10 );
1.890 + m1.insert ( 20 );
1.891 + m1.insert ( 30 );
1.892 +
1.893 + m2.insert ( m1.begin(),m1.end());
1.894 + mmap::iterator i1 = m2.begin();
1.895 + CPPUNIT_ASSERT( *i1 == 10);
1.896 + }
1.897 +
1.898 + {
1.899 + typedef hash_set<int> mmap;
1.900 + mmap m;
1.901 +
1.902 + m.insert ( 10 );
1.903 + m.insert ( 20 );
1.904 + m.insert ( 30 );
1.905 +
1.906 + std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
1.907 + CPPUNIT_ASSERT( *(pair1.first) == 20);
1.908 + CPPUNIT_ASSERT( *(pair1.second) == 30);
1.909 + // negative test case for equal_range where the key value is not present.
1.910 + std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
1.911 + CPPUNIT_ASSERT( pair2.first == m.end());
1.912 + CPPUNIT_ASSERT( pair2.second == m.end()); }
1.913 + __UHEAP_MARKEND;
1.914 + }
1.915 +void HashTest::hash_set_cov4()
1.916 + {
1.917 + __UHEAP_MARK;
1.918 + {
1.919 + typedef hash_set<int> mmap;
1.920 + mmap m;
1.921 +
1.922 + m.insert ( 10 );
1.923 + m.insert ( 20 );
1.924 + m.insert ( 30 );
1.925 +
1.926 + m.erase(m.begin());
1.927 + mmap::iterator i1 = m.begin();
1.928 + CPPUNIT_ASSERT( *i1 == 20);
1.929 + CPPUNIT_ASSERT( m.size() == 2 );
1.930 + m.erase(m.begin(),m.end());
1.931 + CPPUNIT_ASSERT( m.size() == 0 );
1.932 + }
1.933 + {
1.934 + typedef hash_set<int> mmap;
1.935 + mmap m;
1.936 +
1.937 + m.insert ( 10 );
1.938 + m.insert ( 20 );
1.939 + m.insert ( 30 );
1.940 +
1.941 + mmap::iterator i1 = m.find(10);
1.942 + CPPUNIT_ASSERT( *i1 == 10);
1.943 + mmap::const_iterator i2 = m.find(30);
1.944 + CPPUNIT_ASSERT( *i2 == 30);
1.945 + }
1.946 + {
1.947 + typedef hash_set<int> mmap;
1.948 + typedef allocator<std::pair<int, int> > Myalloc;
1.949 + mmap m;
1.950 +
1.951 + mmap::allocator_type al = m.get_allocator();
1.952 + CPPUNIT_ASSERT ((al == Myalloc()) == true);
1.953 +
1.954 + mmap::hasher hfn = m.hash_funct(); // returns the hasher function
1.955 + }
1.956 + __UHEAP_MARKEND;
1.957 + }
1.958 +void HashTest::hash_set_cov5()
1.959 + {
1.960 + __UHEAP_MARK;
1.961 + {
1.962 + typedef hash_set<int> mmap;
1.963 + mmap m1,m2;
1.964 +
1.965 + m1.insert ( 10 );
1.966 + m1.insert ( 20 );
1.967 + m1.insert ( 30 );
1.968 +
1.969 + m2.insert ( m1.begin(),m1.end());
1.970 + mmap::iterator i1 = m2.begin();
1.971 + CPPUNIT_ASSERT( *i1 == 10);
1.972 + }
1.973 + {
1.974 + typedef hash_set<char> mmap;
1.975 + mmap c1;
1.976 + mmap::key_equal cmpfn = c1.key_eq();
1.977 + CPPUNIT_ASSERT( cmpfn('a','a') == true);
1.978 +
1.979 + c1.max_bucket_count(); // for covering the api
1.980 + }
1.981 + {
1.982 + typedef hash_set<int> mmap;
1.983 + mmap m1;
1.984 +
1.985 + m1.insert_noresize ( 10 );
1.986 + m1.insert_noresize ( 20 );
1.987 + m1.insert_noresize ( 30 );
1.988 +
1.989 + mmap::iterator i1 = m1.begin();
1.990 + CPPUNIT_ASSERT( *i1 == 10);
1.991 + }
1.992 + {
1.993 + typedef hash_set<int> mmap;
1.994 + mmap m1;
1.995 + int bcount;
1.996 +
1.997 + m1.insert ( 10 );
1.998 + m1.insert ( 20 );
1.999 + m1.insert ( 30 );
1.1000 +
1.1001 + mmap m2(m1);
1.1002 + mmap::iterator i1 = m2.begin();
1.1003 + CPPUNIT_ASSERT( *i1 == 10);
1.1004 +
1.1005 + mmap m3(10);
1.1006 + bcount = m3.bucket_count();
1.1007 + CPPUNIT_ASSERT( bcount >= 10);
1.1008 +
1.1009 + mmap::hasher hfn = m1.hash_funct();
1.1010 + mmap m4(20,hfn);
1.1011 + bcount = m4.bucket_count();
1.1012 + CPPUNIT_ASSERT( bcount >= 20);
1.1013 +
1.1014 + mmap m5(m1.begin(),m2.end());
1.1015 + CPPUNIT_ASSERT( m5.size() == 3);
1.1016 +
1.1017 + mmap m6(m1.begin(),m2.end(),30);
1.1018 + CPPUNIT_ASSERT( m6.size() == 3);
1.1019 + bcount = m6.bucket_count();
1.1020 + CPPUNIT_ASSERT( bcount >= 30);
1.1021 +
1.1022 + mmap m7(m1.begin(),m2.end(),30,hfn);
1.1023 + CPPUNIT_ASSERT( m7.size() == 3);
1.1024 + bcount = m7.bucket_count();
1.1025 + CPPUNIT_ASSERT( bcount >= 30);
1.1026 +
1.1027 + mmap::key_equal cmpfn;// = c1.key_eq();
1.1028 + mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1.1029 +
1.1030 + mmap m9(30,hfn,cmpfn);
1.1031 + }
1.1032 + __UHEAP_MARKEND;
1.1033 + }
1.1034 +void HashTest::hash_set_cov6()
1.1035 + {
1.1036 + __UHEAP_MARK;
1.1037 + {
1.1038 + typedef hash_set<int> mmap;
1.1039 + mmap m1;
1.1040 +
1.1041 + m1.insert ( 10 );
1.1042 + m1.insert ( 20 );
1.1043 + m1.insert ( 30 );
1.1044 +
1.1045 + CPPUNIT_ASSERT( m1.count(10) == 1);
1.1046 + CPPUNIT_ASSERT( m1.erase(10) == 1);
1.1047 + CPPUNIT_ASSERT( m1.count(10) == 0);
1.1048 + }
1.1049 + {
1.1050 + hash_set <int> hm1;
1.1051 + hash_set <int>::iterator hm1_Iter;
1.1052 + hm1.insert ( 10 );
1.1053 + hm1.insert ( 20 );
1.1054 + hm1.insert ( 30 );
1.1055 + hm1_Iter = hm1.begin( );
1.1056 + CPPUNIT_ASSERT( *hm1_Iter == 10);
1.1057 + hm1_Iter ++ ;
1.1058 + CPPUNIT_ASSERT( *hm1_Iter == 20);
1.1059 + hm1_Iter ++ ;
1.1060 + CPPUNIT_ASSERT( *hm1_Iter == 30);
1.1061 +
1.1062 + }
1.1063 + __UHEAP_MARKEND;
1.1064 + }
1.1065 +
1.1066 +void HashTest::hash_multiset_cov1()
1.1067 + {
1.1068 + __UHEAP_MARK;
1.1069 + {
1.1070 + hash_multiset <int> hm1, hm2;
1.1071 + hash_multiset <int>::iterator hm1_Iter;
1.1072 + hash_multiset <int>::const_iterator hm1_cIter;
1.1073 +
1.1074 + hm1.insert ( 10 );
1.1075 + hm1.insert ( 20 );
1.1076 + hm1.insert ( 30 );
1.1077 + hm2.insert ( 300 );
1.1078 +
1.1079 + hm1.swap( hm2 );
1.1080 + hm1_Iter = hm1.begin( );
1.1081 + CPPUNIT_ASSERT( *hm1_Iter== 300);
1.1082 + hm1_Iter = hm1.end( );
1.1083 + hm1_cIter = hm1.end( );
1.1084 + hm1.clear();
1.1085 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.1086 + CPPUNIT_ASSERT( hm1.empty() == true );
1.1087 + }
1.1088 + {
1.1089 + hash_multiset <int> hm1, hm2;
1.1090 + hash_multiset <int>::iterator hm1_Iter;
1.1091 + hash_multiset <int>::const_iterator hm1_cIter;
1.1092 +
1.1093 + hm1.insert ( 10 );
1.1094 + hm1.insert ( 20 );
1.1095 + hm1.insert ( 30 );
1.1096 + hm2.insert ( 300 );
1.1097 +
1.1098 + swap( hm1,hm2 );
1.1099 + hm1_Iter = hm1.begin( );
1.1100 + CPPUNIT_ASSERT( *hm1_Iter== 300);
1.1101 + hm1_Iter = hm1.end( );
1.1102 + hm1_cIter = hm1.end( );
1.1103 + hm1.clear();
1.1104 + CPPUNIT_ASSERT( hm1.size() == 0 );
1.1105 + CPPUNIT_ASSERT( hm1.empty() == true );
1.1106 + }
1.1107 + __UHEAP_MARKEND;
1.1108 + }
1.1109 +void HashTest::hash_multiset_cov2()
1.1110 + {
1.1111 + __UHEAP_MARK;
1.1112 + {
1.1113 + hash_multiset <int> hm1;
1.1114 + int i,bcount;
1.1115 +
1.1116 + hm1.insert ( 1 );
1.1117 + i = hm1.size( );
1.1118 + CPPUNIT_ASSERT( i == 1);
1.1119 +
1.1120 + i = hm1.max_size(); // for covering the api
1.1121 +
1.1122 + hm1.insert ( 4 );
1.1123 + i = hm1.size( );
1.1124 + CPPUNIT_ASSERT( i == 2);
1.1125 + hm1.resize(10);
1.1126 + bcount = hm1.bucket_count();
1.1127 + CPPUNIT_ASSERT( bcount >= 10);
1.1128 + hm1.elems_in_bucket(1);
1.1129 + }
1.1130 + {
1.1131 + typedef hash_multiset<int> mmap;
1.1132 + mmap m1;
1.1133 +
1.1134 + m1.insert_noresize ( 10 );
1.1135 + m1.insert_noresize ( 20 );
1.1136 + m1.insert_noresize ( 30 );
1.1137 +
1.1138 + mmap::iterator i1 = m1.begin();
1.1139 + CPPUNIT_ASSERT( *i1 == 10);
1.1140 + }
1.1141 + {
1.1142 + typedef hash_multiset<char> mmap;
1.1143 + mmap c1;
1.1144 + mmap::key_equal cmpfn = c1.key_eq();
1.1145 + CPPUNIT_ASSERT( cmpfn('a','a') == true);
1.1146 +
1.1147 + c1.max_bucket_count(); // for covering the api
1.1148 + }
1.1149 + __UHEAP_MARKEND;
1.1150 + }
1.1151 +void HashTest::hash_multiset_cov3()
1.1152 + {
1.1153 + __UHEAP_MARK;
1.1154 + {
1.1155 + typedef hash_multiset<int> mmap;
1.1156 + mmap m1;
1.1157 + int bcount;
1.1158 +
1.1159 + m1.insert ( 10 );
1.1160 + m1.insert ( 20 );
1.1161 + m1.insert ( 30 );
1.1162 +
1.1163 + mmap m2(m1);
1.1164 + mmap::iterator i1 = m2.begin();
1.1165 + CPPUNIT_ASSERT( *i1 == 10);
1.1166 +
1.1167 + mmap m3(10);
1.1168 + bcount = m3.bucket_count();
1.1169 + CPPUNIT_ASSERT( bcount >= 10);
1.1170 +
1.1171 + mmap::hasher hfn = m1.hash_funct();
1.1172 + mmap m4(20,hfn);
1.1173 + bcount = m4.bucket_count();
1.1174 + CPPUNIT_ASSERT( bcount >= 20);
1.1175 +
1.1176 + mmap m5(m1.begin(),m2.end());
1.1177 + CPPUNIT_ASSERT( m5.size() == 3);
1.1178 +
1.1179 + mmap m6(m1.begin(),m2.end(),30);
1.1180 + CPPUNIT_ASSERT( m6.size() == 3);
1.1181 + bcount = m6.bucket_count();
1.1182 + CPPUNIT_ASSERT( bcount >= 30);
1.1183 +
1.1184 + mmap m7(m1.begin(),m2.end(),30,hfn);
1.1185 + CPPUNIT_ASSERT( m7.size() == 3);
1.1186 + bcount = m7.bucket_count();
1.1187 + CPPUNIT_ASSERT( bcount >= 30);
1.1188 +
1.1189 + mmap::key_equal cmpfn;// = c1.key_eq();
1.1190 + mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1.1191 +
1.1192 + mmap m9(30,hfn,cmpfn);
1.1193 + }
1.1194 + __UHEAP_MARKEND;
1.1195 + }