os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/unordered_test.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #include <e32std.h>
    17 #include <vector>
    18 #include <algorithm>
    19 #include <string>
    20 #if defined (STLPORT)
    21 #  include <unordered_map>
    22 #  include <unordered_set>
    23 #endif
    24 
    25 //#include <iostream>
    26 
    27 #include "cppunit/cppunit_proxy.h"
    28 
    29 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    30 using namespace std;
    31 #endif
    32 
    33 //
    34 // TestCase class
    35 //
    36 class UnorderedTest : public CPPUNIT_NS::TestCase
    37 {
    38   CPPUNIT_TEST_SUITE(UnorderedTest);
    39 #if !defined (STLPORT) 
    40   CPPUNIT_IGNORE;
    41 #endif
    42   CPPUNIT_TEST(uset);
    43   CPPUNIT_TEST(umultiset);
    44 #if defined (__DMC__)
    45   CPPUNIT_IGNORE;
    46 #endif
    47   CPPUNIT_TEST(umap);
    48   CPPUNIT_STOP_IGNORE;
    49   CPPUNIT_TEST(umultimap);
    50 #if defined (__DMC__)
    51   CPPUNIT_IGNORE;
    52 #endif
    53   CPPUNIT_TEST(user_case);
    54   CPPUNIT_STOP_IGNORE;
    55   CPPUNIT_TEST(hash_policy);
    56   CPPUNIT_TEST(buckets);
    57 #if defined (__DMC__)
    58   CPPUNIT_IGNORE;
    59 #endif
    60   CPPUNIT_TEST(equal_range);
    61 #if !defined (_STLP_USE_CONTAINERS_EXTENSION)
    62   CPPUNIT_IGNORE;
    63 #endif
    64   CPPUNIT_TEST(template_methods);
    65   CPPUNIT_TEST(unordered_set_cov1);
    66   CPPUNIT_TEST(unordered_set_cov2);
    67   CPPUNIT_TEST(unordered_set_cov3);
    68   CPPUNIT_TEST(unordered_map_cov1);
    69   CPPUNIT_TEST(unordered_map_cov2);
    70   CPPUNIT_TEST(unordered_map_cov3);
    71   CPPUNIT_TEST(unordered_map_cov4);
    72   CPPUNIT_TEST(unordered_map_cov5);
    73   CPPUNIT_TEST(unordered_multimap_cov1);
    74   CPPUNIT_TEST(unordered_multimap_cov2);
    75   CPPUNIT_TEST(unordered_multimap_cov3);
    76   CPPUNIT_TEST(unordered_multimap_cov4);
    77   CPPUNIT_TEST(unordered_multimap_cov5);
    78   CPPUNIT_TEST(unordered_multiset_cov1);
    79   CPPUNIT_TEST(unordered_multiset_cov2);
    80   CPPUNIT_TEST(unordered_multiset_cov3);
    81   CPPUNIT_TEST(unordered_multiset_cov4);
    82   CPPUNIT_TEST_SUITE_END();
    83 
    84 protected:
    85   void uset();
    86   void umultiset();
    87   void umap();
    88   void umultimap();
    89   void user_case();
    90   void hash_policy();
    91   void buckets();
    92   void equal_range();
    93   void template_methods();
    94   void unordered_set_cov1();
    95   void unordered_set_cov2();
    96   void unordered_set_cov3();
    97   void unordered_map_cov1();
    98   void unordered_map_cov2();
    99   void unordered_map_cov3();
   100   void unordered_map_cov4();
   101   void unordered_map_cov5();
   102   void unordered_multimap_cov1();
   103   void unordered_multimap_cov2();
   104   void unordered_multimap_cov3();
   105   void unordered_multimap_cov4();
   106   void unordered_multimap_cov5();
   107   void unordered_multiset_cov1();
   108   void unordered_multiset_cov2();
   109   void unordered_multiset_cov3();
   110   void unordered_multiset_cov4();
   111 };
   112 
   113 CPPUNIT_TEST_SUITE_REGISTRATION(UnorderedTest);
   114 
   115 const int NB_ELEMS = 2000;
   116 
   117 //
   118 // tests implementation
   119 //
   120 void UnorderedTest::uset()
   121 {
   122 #if defined (STLPORT)
   123   typedef unordered_set<int, hash<int>, equal_to<int> > usettype;
   124   usettype us;
   125 
   126   //Small compilation check of the copy constructor:
   127   usettype us2(us);
   128   //And assignment operator
   129   us = us2;
   130 
   131   int i;
   132   pair<usettype::iterator, bool> ret;
   133   for (i = 0; i < NB_ELEMS; ++i) {
   134     ret = us.insert(i);
   135     CPPUNIT_ASSERT( ret.second );
   136     CPPUNIT_ASSERT( *ret.first == i );
   137 
   138     ret = us.insert(i);
   139     CPPUNIT_ASSERT( !ret.second );
   140     CPPUNIT_ASSERT( *ret.first == i );
   141   }
   142 
   143   vector<int> us_val;
   144 
   145   usettype::local_iterator lit, litEnd;
   146   for (i = 0; i < NB_ELEMS; ++i) {
   147     lit = us.begin(us.bucket(i));
   148     litEnd = us.end(us.bucket(i));
   149 
   150     usettype::size_type bucket_pos = us.bucket(*lit);
   151     for (; lit != litEnd; ++lit) {
   152       CPPUNIT_ASSERT( us.bucket(*lit) == bucket_pos );
   153       us_val.push_back(*lit);
   154     }
   155   }
   156 
   157   //A compilation time check to uncomment from time to time
   158   {
   159     //usettype::iterator it;
   160     //CPPUNIT_ASSERT( it != lit );
   161   }
   162 
   163   sort(us_val.begin(), us_val.end());
   164   for (i = 0; i < NB_ELEMS; ++i) {
   165     CPPUNIT_ASSERT( us_val[i] == i );
   166   }
   167 #endif
   168 }
   169 
   170 void UnorderedTest::umultiset()
   171 {
   172 #if defined (STLPORT)
   173   typedef unordered_multiset<int, hash<int>, equal_to<int> > usettype;
   174   usettype us;
   175 
   176   int i;
   177   usettype::iterator ret;
   178   for (i = 0; i < NB_ELEMS; ++i) {
   179     ret = us.insert(i);
   180     CPPUNIT_ASSERT( *ret == i );
   181 
   182     ret = us.insert(i);
   183     CPPUNIT_ASSERT( *ret == i );
   184   }
   185 
   186   CPPUNIT_ASSERT( us.size() == 2 * NB_ELEMS );
   187   vector<int> us_val;
   188 
   189   usettype::local_iterator lit, litEnd;
   190   for (i = 0; i < NB_ELEMS; ++i) {
   191     lit = us.begin(us.bucket(i));
   192     litEnd = us.end(us.bucket(i));
   193 
   194     usettype::size_type bucket_pos = us.bucket(*lit);
   195     for (; lit != litEnd; ++lit) {
   196       CPPUNIT_ASSERT( us.bucket(*lit) == bucket_pos );
   197       us_val.push_back(*lit);
   198     }
   199   }
   200 
   201   sort(us_val.begin(), us_val.end());
   202   for (i = 0; i < NB_ELEMS; ++i) {
   203     CPPUNIT_ASSERT( us_val[2 * i] == i );
   204     CPPUNIT_ASSERT( us_val[2 * i + 1] == i );
   205   }
   206 #endif
   207 }
   208 
   209 void UnorderedTest::umap()
   210 {
   211 #if defined (STLPORT) && !defined (__DMC__)
   212   typedef unordered_map<int, int, hash<int>, equal_to<int> > umaptype;
   213   umaptype us;
   214 
   215   //Compilation check of the [] operator:
   216   umaptype us2;
   217   us[0] = us2[0];
   218   us.clear();
   219 
   220   {
   221     //An other compilation check
   222     typedef unordered_map<int, umaptype> uumaptype;
   223     uumaptype uus;
   224     umaptype const& uref = uus[0];
   225     umaptype ucopy = uus[0];
   226     ucopy = uref;
   227     //Avoids warning:
   228     //(void*)&uref;
   229   }
   230 
   231   int i;
   232   pair<umaptype::iterator, bool> ret;
   233   for (i = 0; i < NB_ELEMS; ++i) {
   234     umaptype::value_type p1(i, i);
   235     ret = us.insert(p1);
   236     CPPUNIT_ASSERT( ret.second );
   237     CPPUNIT_ASSERT( *ret.first == p1 );
   238 
   239     umaptype::value_type p2(i, i + 1);
   240     ret = us.insert(p2);
   241     CPPUNIT_ASSERT( !ret.second );
   242     CPPUNIT_ASSERT( *ret.first == p1 );
   243   }
   244 
   245   {
   246     //Lets look for some values to see if everything is normal:
   247     umaptype::iterator umit;
   248     for (int j = 0; j < NB_ELEMS; j += NB_ELEMS / 100) {
   249       umit = us.find(j);
   250 
   251       CPPUNIT_ASSERT( umit != us.end() );
   252       CPPUNIT_ASSERT( (*umit).second == j );
   253     }
   254   }
   255 
   256   CPPUNIT_ASSERT( us.size() == (size_t)NB_ELEMS );
   257   vector<pair<int, int> > us_val;
   258 
   259   umaptype::local_iterator lit, litEnd;
   260   for (i = 0; i < NB_ELEMS; ++i) {
   261     lit = us.begin(us.bucket(i));
   262     litEnd = us.end(us.bucket(i));
   263 
   264     umaptype::size_type bucket_pos = us.bucket((*lit).first);
   265     for (; lit != litEnd; ++lit) {
   266       CPPUNIT_ASSERT( us.bucket((*lit).first) == bucket_pos );
   267       us_val.push_back(make_pair((*lit).first, (*lit).second));
   268     }
   269   }
   270 
   271   sort(us_val.begin(), us_val.end());
   272   for (i = 0; i < NB_ELEMS; ++i) {
   273     CPPUNIT_ASSERT( us_val[i] == make_pair(i, i) );
   274   }
   275 #endif
   276 }
   277 
   278 void UnorderedTest::umultimap()
   279 {
   280 #if defined (STLPORT)
   281   typedef unordered_multimap<int, int, hash<int>, equal_to<int> > umaptype;
   282   umaptype us;
   283 
   284   int i;
   285   umaptype::iterator ret;
   286   for (i = 0; i < NB_ELEMS; ++i) {
   287     umaptype::value_type p(i, i);
   288     ret = us.insert(p);
   289     CPPUNIT_ASSERT( *ret == p );
   290 
   291     ret = us.insert(p);
   292     CPPUNIT_ASSERT( *ret == p );
   293   }
   294 
   295   CPPUNIT_ASSERT( us.size() == 2 * NB_ELEMS );
   296   typedef pair<int, int> ptype;
   297   vector<ptype> us_val;
   298 
   299   umaptype::local_iterator lit, litEnd;
   300   for (i = 0; i < NB_ELEMS; ++i) {
   301     lit = us.begin(us.bucket(i));
   302     litEnd = us.end(us.bucket(i));
   303 
   304     umaptype::size_type bucket_pos = us.bucket((*lit).first);
   305     for (; lit != litEnd; ++lit) {
   306       CPPUNIT_ASSERT( us.bucket((*lit).first) == bucket_pos );
   307       us_val.push_back(ptype((*lit).first, (*lit).second));
   308     }
   309   }
   310 
   311   sort(us_val.begin(), us_val.end());
   312   for (i = 0; i < NB_ELEMS; ++i) {
   313     ptype p(i, i);
   314     CPPUNIT_ASSERT( us_val[i * 2] == p );
   315     CPPUNIT_ASSERT( us_val[i * 2 + 1] == p );
   316   }
   317 #endif
   318 }
   319 
   320 void UnorderedTest::user_case()
   321 {
   322 #if defined (STLPORT) && !defined (__DMC__)
   323   typedef unordered_map<int, string> UnorderedMap1;
   324   typedef unordered_map<int, UnorderedMap1> UnorderedMap2;
   325 
   326   UnorderedMap1 foo;
   327   UnorderedMap2 bar;
   328 
   329   foo.insert(UnorderedMap1::value_type(1, string("test1")));
   330   foo.insert(UnorderedMap1::value_type(2, string("test2")));
   331   foo.insert(UnorderedMap1::value_type(3, string("test3")));
   332   foo.insert(UnorderedMap1::value_type(4, string("test4")));
   333   foo.insert(UnorderedMap1::value_type(5, string("test5")));
   334 
   335   bar.insert(UnorderedMap2::value_type(0, foo));
   336   UnorderedMap2::iterator it = bar.find(0);
   337   CPPUNIT_ASSERT( it != bar.end() );
   338 
   339   UnorderedMap1 &body = it->second;
   340   UnorderedMap1::iterator cur = body.find(3);
   341   CPPUNIT_ASSERT( cur != body.end() );
   342 
   343   body.erase(body.begin(), body.end());
   344   CPPUNIT_ASSERT( body.empty() );
   345 #endif
   346 }
   347 
   348 void UnorderedTest::hash_policy()
   349 {
   350 #if defined (STLPORT)
   351   unordered_set<int> int_uset;
   352 
   353   CPPUNIT_ASSERT( int_uset.max_load_factor() == 1.0f );
   354   CPPUNIT_ASSERT( int_uset.load_factor() == 0.0f );
   355 
   356   size_t nbInserts = int_uset.bucket_count() - 1;
   357   for (int i = 0; (size_t)i < nbInserts; ++i) {
   358     int_uset.insert(i);
   359   }
   360   CPPUNIT_ASSERT( int_uset.size() == nbInserts );
   361 
   362   int_uset.max_load_factor(0.5f);
   363   int_uset.rehash(0);
   364   CPPUNIT_ASSERT( int_uset.load_factor() < int_uset.max_load_factor() );
   365 
   366   size_t bucketsHint = int_uset.bucket_count() + 1;
   367   int_uset.rehash(bucketsHint);
   368   CPPUNIT_ASSERT( int_uset.bucket_count() >= bucketsHint );
   369 
   370   CPPUNIT_ASSERT( int_uset.key_eq()(10, 10) );
   371   CPPUNIT_ASSERT( int_uset.hash_function()(10) == 10 );
   372 #endif
   373 }
   374 
   375 void UnorderedTest::buckets()
   376 {
   377 #if defined (STLPORT) 
   378   unordered_set<int> int_uset;
   379 
   380   CPPUNIT_ASSERT( int_uset.bucket_count() < int_uset.max_bucket_count() );
   381 
   382   int i;
   383   size_t nbBuckets = int_uset.bucket_count();
   384   size_t nbInserts = int_uset.bucket_count() - 1;
   385   for (i = 0; (size_t)i < nbInserts; ++i) {
   386     int_uset.insert(i);
   387   }
   388   CPPUNIT_ASSERT( nbBuckets == int_uset.bucket_count() );
   389 
   390   size_t bucketSizes = 0;
   391   for (i = 0; (size_t)i < nbBuckets; ++i) {
   392     bucketSizes += int_uset.bucket_size(i);
   393   }
   394   CPPUNIT_ASSERT( bucketSizes == int_uset.size() );
   395 #endif
   396 }
   397 
   398 void UnorderedTest::equal_range()
   399 {
   400 #if defined (STLPORT) && !defined (__DMC__)
   401   typedef unordered_multiset<size_t> umset;
   402   {
   403     //General test
   404     umset iumset;
   405     iumset.max_load_factor(10.0f);
   406 
   407     size_t nbBuckets = iumset.bucket_count();
   408 
   409     for (size_t i = 0; i < nbBuckets; ++i) {
   410       iumset.insert(i);
   411       iumset.insert(i + nbBuckets);
   412       iumset.insert(i + 2 * nbBuckets);
   413       iumset.insert(i + 3 * nbBuckets);
   414       iumset.insert(i + 4 * nbBuckets);
   415     }
   416 
   417     CPPUNIT_ASSERT( nbBuckets == iumset.bucket_count() );
   418     CPPUNIT_ASSERT( iumset.size() == 5 * nbBuckets );
   419 
   420     pair<umset::iterator, umset::iterator> p = iumset.equal_range(1);
   421     CPPUNIT_ASSERT( p.first != p.second );
   422 
   423     size_t nbElems = iumset.size();
   424     nbElems -= distance(p.first, p.second);
   425     for (umset::iterator j = p.first; j != p.second;) {
   426       iumset.erase(j++);
   427     }
   428 
   429     CPPUNIT_ASSERT( nbElems == iumset.size() );
   430 
   431     p = iumset.equal_range(2);
   432     CPPUNIT_ASSERT( p.first != p.second );
   433     nbElems -= distance(p.first, p.second);
   434     iumset.erase(p.first, p.second);
   435     CPPUNIT_ASSERT( nbElems == iumset.size() );
   436   }
   437 
   438   {
   439     //More specific test that tries to put many values in the same bucket
   440     umset iumset;
   441 
   442     size_t i;
   443     const size_t nbBuckets = iumset.bucket_count();
   444     const size_t targetedBucket = nbBuckets / 2;
   445 
   446     //Lets put 10 values in the targeted bucket:
   447     for (i = 0; i < 10; ++i) {
   448       iumset.insert(targetedBucket + (i * nbBuckets));
   449     }
   450 
   451     //We put again 10 values in the targeted bucket and in reverse order:
   452     for (i = 9; i <= 10; --i) {
   453       iumset.insert(targetedBucket + (i * nbBuckets));
   454     }
   455 
   456     //Now we put some more elements until hash container is resized:
   457     i = 0;
   458     while (iumset.bucket_count() == nbBuckets) {
   459       iumset.insert(i++);
   460     }
   461 
   462     //CPPUNIT_ASSERT( iumset.bucket_size(targetedBucket) == 21 );
   463 
   464     pair<umset::iterator, umset::iterator> p = iumset.equal_range(targetedBucket);
   465     CPPUNIT_ASSERT( p.first != p.second );
   466     CPPUNIT_ASSERT( distance(p.first, p.second) == 3 );
   467   }
   468 
   469   {
   470     srand(0);
   471     for (int runs = 0; runs < 2; ++runs) {
   472       size_t magic = rand();
   473       umset hum;
   474       size_t c = 0;
   475       for (int i = 0; i < 10000; ++i) {
   476         if ((rand() % 500) == 0) {
   477           hum.insert(magic);
   478           ++c;
   479         }
   480         else {
   481           size_t r;
   482           while ((r = rand()) == magic);
   483           hum.insert(r);
   484         }
   485 
   486         /*
   487         if ((float)(hum.size() + 1) / (float)hum.bucket_count() > hum.max_load_factor()) {
   488           cout << "Hash container dump: Nb elems: " << hum.size() << ", Nb buckets: " << hum.bucket_count() << "\n";
   489           for (size_t b = 0; b < hum.bucket_count(); ++b) {
   490             if (hum.bucket_size(b) != 0) {
   491               umset::local_iterator litBegin(hum.begin(b)), litEnd(hum.end(b));
   492               cout << "B" << b << ": ";
   493               for (umset::local_iterator lit = litBegin; lit != litEnd; ++lit) {
   494                 if (lit != litBegin) {
   495                   cout << " - ";
   496                 }
   497                 cout << *lit;
   498               }
   499               cout << "\n";
   500             }
   501           }
   502           cout << endl;
   503         }
   504         */
   505       }
   506       CPPUNIT_ASSERT( hum.count(magic) == c );
   507     }
   508   }
   509 #endif
   510 }
   511 
   512 struct Key
   513 {
   514   Key() : m_data(0) {}
   515   explicit Key(int data) : m_data(data) {}
   516 
   517   int m_data;
   518 };
   519 
   520 struct KeyHash
   521 {
   522   size_t operator () (Key key) const
   523   { return (size_t)key.m_data; }
   524 
   525   size_t operator () (int data) const
   526   { return (size_t)data; }
   527 };
   528 
   529 struct KeyEqual
   530 {
   531   bool operator () (Key lhs, Key rhs) const
   532   { return lhs.m_data == rhs.m_data; }
   533 
   534   bool operator () (Key lhs, int rhs) const
   535   { return lhs.m_data == rhs; }
   536 
   537   bool operator () (int lhs, Key rhs) const
   538   { return lhs == rhs.m_data; }
   539 };
   540 
   541 struct KeyHashPtr
   542 {
   543   size_t operator () (Key const volatile *key) const
   544   { return (size_t)key->m_data; }
   545 
   546   size_t operator () (int data) const
   547   { return (size_t)data; }
   548 };
   549 
   550 struct KeyEqualPtr
   551 {
   552   bool operator () (Key const volatile *lhs, Key const volatile *rhs) const
   553   { return lhs->m_data == rhs->m_data; }
   554 
   555   bool operator () (Key const volatile *lhs, int rhs) const
   556   { return lhs->m_data == rhs; }
   557 
   558   bool operator () (int lhs, Key const volatile *rhs) const
   559   { return lhs == rhs->m_data; }
   560 };
   561 
   562 void UnorderedTest::template_methods()
   563 {
   564 #if defined (STLPORT) && defined (_STLP_USE_CONTAINERS_EXTENSION)
   565   {
   566     typedef unordered_set<Key, KeyHash, KeyEqual> Container;
   567     Container cont;
   568     cont.insert(Key(1));
   569     cont.insert(Key(2));
   570     cont.insert(Key(3));
   571     cont.insert(Key(4));
   572 
   573     CPPUNIT_ASSERT( cont.count(Key(1)) == 1 );
   574     CPPUNIT_ASSERT( cont.count(1) == 1 );
   575     CPPUNIT_ASSERT( cont.count(5) == 0 );
   576 
   577     CPPUNIT_ASSERT( cont.find(2) != cont.end() );
   578     CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
   579 
   580     Container const& ccont = cont;
   581     CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
   582     CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) );
   583     CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
   584   }
   585 
   586   {
   587     typedef unordered_set<Key*, KeyHashPtr, KeyEqualPtr> Container;
   588     Container cont;
   589     Key key1(1), key2(2), key3(3), key4(4);
   590     cont.insert(&key1);
   591     cont.insert(&key2);
   592     cont.insert(&key3);
   593     cont.insert(&key4);
   594 
   595     CPPUNIT_ASSERT( cont.count(1) == 1 );
   596     CPPUNIT_ASSERT( cont.count(5) == 0 );
   597 
   598     CPPUNIT_ASSERT( cont.find(2) != cont.end() );
   599     CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
   600 
   601     Container const& ccont = cont;
   602     CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
   603     CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) );
   604     CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
   605   }
   606   {
   607     typedef unordered_multiset<Key, KeyHash, KeyEqual> Container;
   608     Container cont;
   609     cont.insert(Key(1));
   610     cont.insert(Key(2));
   611     cont.insert(Key(1));
   612     cont.insert(Key(2));
   613 
   614     CPPUNIT_ASSERT( cont.count(Key(1)) == 2 );
   615     CPPUNIT_ASSERT( cont.count(1) == 2 );
   616     CPPUNIT_ASSERT( cont.count(5) == 0 );
   617 
   618     CPPUNIT_ASSERT( cont.find(2) != cont.end() );
   619     CPPUNIT_ASSERT( cont.equal_range(1) != make_pair(cont.end(), cont.end()) );
   620 
   621     Container const& ccont = cont;
   622     CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
   623     CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) );
   624     CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.end(), ccont.end()) );
   625   }
   626 
   627   {
   628     typedef unordered_multiset<Key const volatile*, KeyHashPtr, KeyEqualPtr> Container;
   629     Container cont;
   630     Key key1(1), key2(2), key3(3), key4(4);
   631     cont.insert(&key1);
   632     cont.insert(&key2);
   633     cont.insert(&key3);
   634     cont.insert(&key4);
   635 
   636     CPPUNIT_ASSERT( cont.count(1) == 1 );
   637     CPPUNIT_ASSERT( cont.count(5) == 0 );
   638 
   639     CPPUNIT_ASSERT( cont.find(2) != cont.end() );
   640     CPPUNIT_ASSERT( cont.equal_range(2) != make_pair(cont.begin(), cont.end()) );
   641 
   642     Container const& ccont = cont;
   643     CPPUNIT_ASSERT( ccont.find(2) != ccont.end() );
   644     CPPUNIT_ASSERT( ccont.bucket(2) == ccont.bucket(2) );
   645     CPPUNIT_ASSERT( ccont.equal_range(2) != make_pair(ccont.begin(), ccont.end()) );
   646   }
   647 #endif
   648 }
   649 void UnorderedTest::unordered_set_cov1()
   650 	{
   651 	__UHEAP_MARK;		
   652 		{
   653 		typedef unordered_set<char> Myset;	
   654 		Myset c1,c2; 
   655 		
   656 	    c1.insert('a'); 
   657 	    c1.insert('b'); 
   658 	    c1.insert('c'); 
   659 
   660 	    c2.insert('d'); 
   661 	    c2.insert('e'); 
   662 	    c2.insert('f'); 
   663 	 
   664 	    c1.swap(c2); 
   665 	    Myset::const_iterator it1 = c1.begin();
   666 	    Myset::const_iterator it2 = c2.begin(); 
   667 	    CPPUNIT_ASSERT( *it1 == 'd' );
   668 	    CPPUNIT_ASSERT( *it2 == 'a' );
   669 	    it1++;it2++;
   670 	    CPPUNIT_ASSERT( *it1 == 'e' );
   671 	    CPPUNIT_ASSERT( *it2 == 'b' );
   672 	    it1++;it2++;
   673 	    CPPUNIT_ASSERT( *it1 == 'f' );
   674 	    CPPUNIT_ASSERT( *it2 == 'c' );
   675 		}
   676 		{
   677 		typedef unordered_set<char> Myset;	
   678 		Myset c1,c2; 
   679 		
   680 	    c1.insert('a'); 
   681 	    c1.insert('b'); 
   682 	    c1.insert('c'); 
   683 
   684 	    c2.insert('d'); 
   685 	    c2.insert('e'); 
   686 	    c2.insert('f'); 
   687 	 
   688 	    swap(c1,c2); 
   689 		Myset::const_iterator it1 = c1.begin();
   690 		Myset::const_iterator it2 = c2.begin(); 
   691 	    CPPUNIT_ASSERT( *it1 == 'd' );
   692 	    CPPUNIT_ASSERT( *it2 == 'a' );
   693 	    it1++;it2++;
   694 	    CPPUNIT_ASSERT( *it1 == 'e' );
   695 	    CPPUNIT_ASSERT( *it2 == 'b' );
   696 	    it1++;it2++;
   697 	    CPPUNIT_ASSERT( *it1 == 'f' );
   698 	    CPPUNIT_ASSERT( *it2 == 'c' );
   699 		}
   700 		{
   701 		typedef unordered_set<char> Myset;	
   702 		Myset c1;
   703 		
   704 		c1.max_size();
   705 		}
   706 		__UHEAP_MARKEND;
   707 	}
   708 void UnorderedTest::unordered_set_cov2()
   709 	{
   710 	__UHEAP_MARK;
   711 		{
   712 		typedef unordered_set<char> Myset; 
   713 		Myset c1; 
   714 		 
   715 	    c1.insert('a'); 
   716 	    c1.insert('b'); 
   717 	    c1.insert('c'); 
   718 	    
   719 	    c1.clear(); 
   720 		CPPUNIT_ASSERT(c1.size() == 0 );
   721 		CPPUNIT_ASSERT(c1.empty() );
   722 		}
   723 		{
   724 		typedef unordered_set<char> Myset; 
   725 		Myset c1; 
   726 		 
   727 	    c1.insert('a'); 
   728 	    c1.insert('b'); 
   729 	    c1.insert('c'); 
   730 	    
   731 	    Myset::const_iterator it = c1.end();
   732 	    //it--;
   733 	    //CPPUNIT_ASSERT(*it == 'a' );
   734 	    
   735 	    c1.max_size();
   736 		}
   737 		{
   738 		typedef unordered_set<char> Myset; 
   739 		Myset c1; 
   740 		 
   741 	    c1.insert('a'); 
   742 	    c1.insert('b'); 
   743 	    c1.insert('c'); 
   744 	    
   745 	    c1.erase(c1.begin()); 
   746 	    Myset::iterator it2 = c1.begin();
   747 	    CPPUNIT_ASSERT(*it2 == 'b' );
   748 	    
   749 	    c1.erase(c1.begin(), c1.end()); 
   750 	    CPPUNIT_ASSERT(c1.size() == 0 );
   751 		}
   752 		{
   753 		typedef unordered_set<char> Myset; 
   754 		Myset c1; 
   755 		 
   756 	    c1.insert('a'); 
   757 	    c1.insert('b'); 
   758 	    c1.insert('c');
   759 		CPPUNIT_ASSERT( c1.erase('b')  == 1);	
   760 		}
   761 		__UHEAP_MARKEND;
   762 	}
   763 void UnorderedTest::unordered_set_cov3()
   764 	{
   765 	__UHEAP_MARK;
   766 		{
   767 		typedef unordered_set<char> Mymap; 
   768 		typedef allocator<std::pair<const char, int> > Myalloc;
   769 		Mymap c1; 
   770 		 
   771 	    Mymap::allocator_type al = c1.get_allocator(); 
   772 	    CPPUNIT_ASSERT ((al == Myalloc()) == true);
   773 
   774 		}
   775 		__UHEAP_MARKEND;
   776     }
   777 
   778 void UnorderedTest::unordered_map_cov1()
   779 	{
   780 	__UHEAP_MARK;
   781 		{
   782 		typedef unordered_map<char, int> Mymap;
   783 		Mymap c1; 
   784 		 
   785 	    c1.insert(Mymap::value_type('a', 1)); 
   786 	    c1.insert(Mymap::value_type('b', 2)); 
   787 	    c1.insert(Mymap::value_type('c', 3)); 
   788 	    
   789 	    Mymap::const_iterator it = c1.begin(); 
   790 	    CPPUNIT_ASSERT( it->first == 'a');
   791 	    CPPUNIT_ASSERT( it->second  == 1);
   792 
   793 	    Mymap::const_iterator it1 = c1.end();
   794 	    
   795 	    Mymap::const_local_iterator lit = c1.begin(c1.bucket('a')); 
   796 	    CPPUNIT_ASSERT( lit->first == 'a');
   797 	    CPPUNIT_ASSERT( lit->second  == 1);
   798 	    
   799 	    Mymap::const_local_iterator lit1 = c1.end(c1.bucket('a')); 
   800 		}
   801 		{
   802 		typedef unordered_map<char, int> Mymap; 
   803 		Mymap c1; 
   804 		 
   805 	    c1.insert(Mymap::value_type('a', 1)); 
   806 	    c1.insert(Mymap::value_type('b', 2)); 
   807 	    c1.insert(Mymap::value_type('c', 3)); 
   808 	    c1.bucket_count();
   809 	    
   810 	    Mymap::size_type bs = c1.bucket('a'); 
   811 	    CPPUNIT_ASSERT( c1.bucket_size(bs)  == 1);
   812 	    
   813 	    CPPUNIT_ASSERT( c1.count('A')  == 0);
   814 	    CPPUNIT_ASSERT( c1.count('b')  == 1);
   815 	    CPPUNIT_ASSERT( c1.count('C')  == 0);
   816 		}
   817 		__UHEAP_MARKEND;
   818 	}
   819 void UnorderedTest::unordered_map_cov2()
   820 	{
   821 	__UHEAP_MARK;
   822 		{
   823 		typedef unordered_map<char, int> Mymap; 
   824 		Mymap c1; 
   825 		 
   826 	    c1.insert(Mymap::value_type('a', 1)); 
   827 	    c1.insert(Mymap::value_type('b', 2)); 
   828 	    c1.insert(Mymap::value_type('c', 3)); 
   829 
   830 	    std::pair<Mymap::iterator, Mymap::iterator> pair1 = c1.equal_range('b'); 
   831 	    CPPUNIT_ASSERT( pair1.first->first == 'b');
   832 	    CPPUNIT_ASSERT( pair1.first->second  == 2);
   833 	    
   834 	    std::pair<Mymap::iterator, Mymap::const_iterator> pair2 = c1.equal_range('c'); 
   835 	    CPPUNIT_ASSERT( pair2.first->first == 'c');
   836 	    CPPUNIT_ASSERT( pair2.first->second  == 3);
   837 		}
   838 		{
   839 		typedef unordered_map<char, int> Mymap; 
   840 		Mymap c1; 
   841 		 
   842 	    c1.insert(Mymap::value_type('a', 1)); 
   843 	    c1.insert(Mymap::value_type('b', 2)); 
   844 	    c1.insert(Mymap::value_type('c', 3)); 
   845 	
   846 	    c1.erase(c1.begin()); 
   847 	    Mymap::iterator it2 = c1.begin();
   848 	    CPPUNIT_ASSERT( it2->first == 'b');
   849 	    CPPUNIT_ASSERT( it2->second  == 2);
   850 	    
   851 	    CPPUNIT_ASSERT( c1.erase('b')  == 1);
   852 		}
   853 		{
   854 		typedef unordered_map<char, int> Mymap;	
   855 		Mymap c1; 
   856 		 
   857 	    c1.insert(Mymap::value_type('a', 1)); 
   858 	    c1.insert(Mymap::value_type('b', 2)); 
   859 	    c1.insert(Mymap::value_type('c', 3)); 
   860 
   861 	    Mymap::iterator it = c1.find('b'); 
   862 	    CPPUNIT_ASSERT( it->first == 'b');
   863 	    CPPUNIT_ASSERT( it->second  == 2);
   864 	    
   865 	    // negative test case where the element to find is not present in the 
   866 	    // unordered_map.
   867 	    Mymap::iterator it1 = c1.find('d');
   868 	    Mymap::iterator it2 = c1.end();
   869 	    CPPUNIT_ASSERT( it1 == it2);
   870 		}
   871 		__UHEAP_MARKEND;
   872 	}
   873 void UnorderedTest::unordered_map_cov3()
   874 	{
   875 	__UHEAP_MARK;
   876 		{
   877 		typedef unordered_map<char, int> Mymap; 
   878 		typedef allocator<std::pair<const char, int> > Myalloc;
   879 		Mymap c1; 
   880 		 
   881 	    Mymap::allocator_type al = c1.get_allocator(); 
   882 	    CPPUNIT_ASSERT ((al == Myalloc()) == true);
   883 	    
   884 	    Mymap::hasher hfn = c1.hash_function(); 
   885 	    hfn('a');// returns the hash function object
   886 		}
   887 		{
   888 		typedef unordered_map<char, int> Mymap; 
   889 		Mymap c1,c2; 
   890 		 
   891 	    c1.insert(Mymap::value_type('a', 1)); 
   892 	    c1.insert(Mymap::value_type('b', 2)); 
   893 	    c1.insert(Mymap::value_type('c', 3)); 
   894 	    
   895 	    Mymap::iterator it2;
   896 	    
   897 	    c2.insert(c1.begin(), c1.end()); 
   898 	    it2 = c2.begin();
   899 	    CPPUNIT_ASSERT( it2->first == 'a');
   900 	    CPPUNIT_ASSERT( it2->second  == 1);
   901 		}		
   902 		{
   903 		typedef unordered_map<char, int> Mymap; 
   904 		Mymap c1; 
   905 		Mymap::key_equal cmpfn = c1.key_eq(); 
   906 	    CPPUNIT_ASSERT( cmpfn('a','a') == true);
   907 		}
   908 		__UHEAP_MARKEND;
   909 	}
   910 void UnorderedTest::unordered_map_cov4()
   911 	{
   912 	__UHEAP_MARK;
   913 		{
   914 		typedef unordered_map<char, int> Mymap; 
   915 		Mymap c1,c2; 
   916 		 
   917 	    c1.insert(Mymap::value_type('a', 1)); 
   918 	    c1.insert(Mymap::value_type('b', 2)); 
   919 	    c1.insert(Mymap::value_type('c', 3)); 
   920 	    
   921 	    c2.insert(Mymap::value_type('d', 4)); 
   922 	    c2.insert(Mymap::value_type('e', 5)); 
   923 	    c2.insert(Mymap::value_type('f', 6)); 
   924 
   925 	    c1.swap(c2); 
   926 	    
   927 	    Mymap::iterator it1 = c1.begin();
   928 	    CPPUNIT_ASSERT( it1->first == 'd');
   929 	    CPPUNIT_ASSERT( it1->second  == 4);
   930 	    it1++;
   931 	    CPPUNIT_ASSERT( it1->first == 'e');
   932 	    CPPUNIT_ASSERT( it1->second  == 5);
   933 	    it1++;
   934 	    CPPUNIT_ASSERT( it1->first == 'f');
   935 	    CPPUNIT_ASSERT( it1->second  == 6);
   936 		}
   937 		{
   938 		typedef unordered_map<char, int> Mymap; 
   939 		Mymap c1,c2; 
   940 		 
   941 	    c1.insert(Mymap::value_type('a', 1)); 
   942 	    c1.insert(Mymap::value_type('b', 2)); 
   943 	    c1.insert(Mymap::value_type('c', 3)); 
   944 	    
   945 	    c2.insert(Mymap::value_type('d', 4)); 
   946 	    c2.insert(Mymap::value_type('e', 5)); 
   947 	    c2.insert(Mymap::value_type('f', 6)); 
   948 
   949 	    swap(c1,c2); 
   950 	    
   951 	    Mymap::iterator it1 = c1.begin();
   952 	    CPPUNIT_ASSERT( it1->first == 'd');
   953 	    CPPUNIT_ASSERT( it1->second  == 4);
   954 	    it1++;
   955 	    CPPUNIT_ASSERT( it1->first == 'e');
   956 	    CPPUNIT_ASSERT( it1->second  == 5);
   957 	    it1++;
   958 	    CPPUNIT_ASSERT( it1->first == 'f');
   959 	    CPPUNIT_ASSERT( it1->second  == 6);
   960 		}
   961 		__UHEAP_MARKEND;
   962 	}
   963 void UnorderedTest::unordered_map_cov5()
   964 	{
   965 	__UHEAP_MARK;
   966 		{
   967 		typedef unordered_map<char, int> Mymap; 
   968 		Mymap c1; 
   969 		float a,b; 
   970 	    c1.insert(Mymap::value_type('a', 1)); 
   971 	    c1.insert(Mymap::value_type('b', 2)); 
   972 	    c1.insert(Mymap::value_type('c', 3)); 
   973 	    a = (float)( (float)c1.size()/(float)c1.bucket_count() )  ;
   974 	    b = (float)c1.load_factor();
   975 	    CPPUNIT_ASSERT( a == b );
   976 	    
   977 	    c1.max_load_factor(0.10f); 
   978 	    CPPUNIT_ASSERT( c1.max_load_factor() == 0.1f );
   979 	    
   980 	    CPPUNIT_ASSERT( c1.max_bucket_count() >= c1.bucket_count() );
   981 	    c1.rehash(100); 
   982 		}
   983 		{
   984 		typedef unordered_map<char, int> Mymap;
   985 		Mymap c1;
   986 		c1.max_size();
   987 		}
   988 		{
   989 		typedef unordered_map<char, int> Mymap;	
   990 		Mymap c1; 
   991 		 
   992 	    c1.insert(Mymap::value_type('a', 1)); 
   993 	    c1.insert(Mymap::value_type('b', 2)); 
   994 	    c1.insert(Mymap::value_type('c', 3)); 
   995 
   996 	    Mymap c3(c1.begin(),c1.end(),8,hash<char>(),equal_to<char>(),allocator<std::pair<const char, int> >()); 
   997 	    Mymap::iterator it1 = c3.begin();
   998 	    CPPUNIT_ASSERT( it1->first == 'a');
   999 	    CPPUNIT_ASSERT( it1->second  == 1);
  1000 	    it1++;
  1001 	    CPPUNIT_ASSERT( it1->first == 'b');
  1002 	    CPPUNIT_ASSERT( it1->second  == 2);
  1003 	    it1++;
  1004 	    CPPUNIT_ASSERT( it1->first == 'c');
  1005 	    CPPUNIT_ASSERT( it1->second  == 3);
  1006 
  1007 		}
  1008 		__UHEAP_MARKEND;
  1009 	}
  1010 
  1011 void UnorderedTest::unordered_multimap_cov1()
  1012 	{
  1013 	__UHEAP_MARK;
  1014 		{
  1015 		typedef unordered_multimap<char, int> Mymap;
  1016 		Mymap c1; 
  1017 		 
  1018 	    c1.insert(Mymap::value_type('a', 1)); 
  1019 	    c1.insert(Mymap::value_type('b', 2)); 
  1020 	    c1.insert(Mymap::value_type('c', 3)); 
  1021 
  1022 	    Mymap::const_iterator it = c1.begin(); 
  1023 	    Mymap::iterator it2 = c1.begin(); 
  1024 	    
  1025 	    CPPUNIT_ASSERT( it->first == it2->first);
  1026 	    CPPUNIT_ASSERT( it->second  == it2->second);
  1027 	    
  1028 	    Mymap::const_local_iterator lit = c1.begin(c1.bucket('a')); 
  1029 	    CPPUNIT_ASSERT( lit->first == 'a');
  1030 	    CPPUNIT_ASSERT( lit->second  == 1);
  1031 		}
  1032 		{
  1033 		typedef unordered_multimap<char, int> Mymap; 
  1034 		Mymap c1; 
  1035 		 
  1036 	    c1.insert(Mymap::value_type('a', 1)); 
  1037 	    c1.insert(Mymap::value_type('b', 2)); 
  1038 	    c1.insert(Mymap::value_type('c', 3)); 
  1039 	    c1.bucket_count();
  1040 	    
  1041 	    Mymap::size_type bs = c1.bucket('a'); 
  1042 	    CPPUNIT_ASSERT( c1.bucket_size(bs)  == 1);
  1043 	    
  1044 	    CPPUNIT_ASSERT( c1.count('A')  == 0);
  1045 	    CPPUNIT_ASSERT( c1.count('b')  == 1);
  1046 	    CPPUNIT_ASSERT( c1.count('C')  == 0);
  1047 		}
  1048 		{
  1049 		typedef unordered_multimap<char, int> Mymap; 
  1050 		Mymap c1; 
  1051 		 
  1052 	    c1.insert(Mymap::value_type('a', 1)); 
  1053 	    c1.insert(Mymap::value_type('b', 2)); 
  1054 	    c1.insert(Mymap::value_type('c', 3)); 
  1055 	    
  1056 	    c1.clear(); 
  1057 	    CPPUNIT_ASSERT( c1.size() == 0);
  1058 	    CPPUNIT_ASSERT( c1.empty() == true);
  1059 		}
  1060 		__UHEAP_MARKEND;
  1061 	}
  1062 void UnorderedTest::unordered_multimap_cov2()
  1063 	{
  1064 	__UHEAP_MARK;
  1065 		{
  1066 		typedef unordered_multimap<char, int> Mymap; 
  1067 		Mymap c1; 
  1068 		 
  1069 	    c1.insert(Mymap::value_type('a', 1)); 
  1070 	
  1071 	    Mymap::const_local_iterator lit = c1.end(c1.bucket('a')); 
  1072 		}
  1073 		{
  1074 		typedef unordered_multimap<char, int> Mymap; 
  1075 		Mymap c1; 
  1076 		 
  1077 	    c1.insert(Mymap::value_type('a', 1)); 
  1078 	    c1.insert(Mymap::value_type('b', 2)); 
  1079 	    c1.insert(Mymap::value_type('c', 3)); 
  1080 
  1081 	    std::pair<Mymap::iterator, Mymap::iterator> pair1 = c1.equal_range('b'); 
  1082 	    CPPUNIT_ASSERT( pair1.first->first == 'b');
  1083 	    CPPUNIT_ASSERT( pair1.first->second  == 2);
  1084 	    
  1085 	    std::pair<Mymap::iterator, Mymap::const_iterator> pair2 = c1.equal_range('c'); 
  1086 	    CPPUNIT_ASSERT( pair2.first->first == 'c');
  1087 	    CPPUNIT_ASSERT( pair2.first->second  == 3);
  1088 		}
  1089 		{
  1090 		typedef unordered_multimap<char, int> Mymap; 
  1091 		Mymap c1; 
  1092 		 
  1093 	    c1.insert(Mymap::value_type('a', 1)); 
  1094 	    c1.insert(Mymap::value_type('b', 2)); 
  1095 	    c1.insert(Mymap::value_type('c', 3)); 
  1096 	
  1097 	    c1.erase(c1.begin()); 
  1098 	    Mymap::iterator it2 = c1.begin();
  1099 	    CPPUNIT_ASSERT( it2->first == 'b');
  1100 	    CPPUNIT_ASSERT( it2->second  == 2);
  1101 	    
  1102 	    CPPUNIT_ASSERT( c1.erase('b')  == 1);
  1103 	    
  1104 	    c1.erase(c1.begin(), c1.end()); 
  1105 	    CPPUNIT_ASSERT( c1.empty() );
  1106 		}
  1107 		__UHEAP_MARKEND;
  1108 	}
  1109 void UnorderedTest::unordered_multimap_cov3()
  1110 	{
  1111 	__UHEAP_MARK;
  1112 		{
  1113 		typedef unordered_map<char, int> Mymap;	
  1114 		Mymap c1; 
  1115 		 
  1116 	    c1.insert(Mymap::value_type('a', 1)); 
  1117 	    c1.insert(Mymap::value_type('b', 2)); 
  1118 	    c1.insert(Mymap::value_type('c', 3)); 
  1119 
  1120 	    Mymap::iterator it = c1.find('b'); 
  1121 	    CPPUNIT_ASSERT( it->first == 'b');
  1122 	    CPPUNIT_ASSERT( it->second  == 2);
  1123 	    
  1124 	    Mymap::const_iterator it1 = c1.find('c'); 
  1125 	    CPPUNIT_ASSERT( it1->first == 'c');
  1126 	    CPPUNIT_ASSERT( it1->second  == 3);
  1127 		}
  1128 		{
  1129 		typedef unordered_multimap<char, int> Mymap; 
  1130 		typedef allocator<std::pair<const char, int> > Myalloc;
  1131 		Mymap c1; 
  1132 		 
  1133 	    Mymap::allocator_type al = c1.get_allocator(); 
  1134 	    CPPUNIT_ASSERT ((al == Myalloc()) == true);
  1135 	    
  1136 	    Mymap::hasher hfn = c1.hash_function(); 
  1137 	    hfn('a');// returns the hash function object
  1138 		}
  1139 		{
  1140 		typedef unordered_multimap<char, int> Mymap; 
  1141 		Mymap c1,c2; 
  1142 		 
  1143 	    c1.insert(Mymap::value_type('a', 1)); 
  1144 	    c1.insert(Mymap::value_type('b', 2)); 
  1145 	    c1.insert(Mymap::value_type('c', 3)); 
  1146 	    
  1147 	    Mymap::iterator it2;
  1148 	    
  1149 	    c2.insert(c1.begin(), c1.end()); 
  1150 	    it2 = c2.begin();
  1151 	    CPPUNIT_ASSERT( it2->first == 'a');
  1152 	    CPPUNIT_ASSERT( it2->second  == 1);
  1153 		}
  1154 		__UHEAP_MARKEND;
  1155 	}
  1156 void UnorderedTest::unordered_multimap_cov4()
  1157 	{
  1158 	__UHEAP_MARK;
  1159 		{
  1160 		typedef unordered_multimap<char, int> Mymap; 
  1161 		Mymap c1; 
  1162 		Mymap::key_equal cmpfn = c1.key_eq(); 
  1163 		CPPUNIT_ASSERT( cmpfn('a','a') == true);
  1164 		}
  1165 		{
  1166 		typedef unordered_multimap<char, int> Mymap; 
  1167 		Mymap c1,c2; 
  1168 			 
  1169 		c1.insert(Mymap::value_type('a', 1)); 
  1170 		c1.insert(Mymap::value_type('b', 2)); 
  1171 		c1.insert(Mymap::value_type('c', 3)); 
  1172 		    
  1173 		c2.insert(Mymap::value_type('d', 4)); 
  1174 		c2.insert(Mymap::value_type('e', 5)); 
  1175 		c2.insert(Mymap::value_type('f', 6)); 
  1176 
  1177 		c1.swap(c2); 
  1178 		    
  1179 		Mymap::iterator it1 = c1.begin();
  1180 		CPPUNIT_ASSERT( it1->first == 'd');
  1181 		CPPUNIT_ASSERT( it1->second  == 4);
  1182 		it1++;
  1183 		CPPUNIT_ASSERT( it1->first == 'e');
  1184 		CPPUNIT_ASSERT( it1->second  == 5);
  1185 		it1++;
  1186 		CPPUNIT_ASSERT( it1->first == 'f');
  1187 		CPPUNIT_ASSERT( it1->second  == 6);
  1188 		}
  1189 		{
  1190 		typedef unordered_multimap<char, int> Mymap; 
  1191 		Mymap c1,c2; 
  1192 			 
  1193 		c1.insert(Mymap::value_type('a', 1)); 
  1194 		c1.insert(Mymap::value_type('b', 2)); 
  1195 		c1.insert(Mymap::value_type('c', 3)); 
  1196 		    
  1197 		c2.insert(Mymap::value_type('d', 4)); 
  1198 		c2.insert(Mymap::value_type('e', 5)); 
  1199 		c2.insert(Mymap::value_type('f', 6)); 
  1200 
  1201 		swap(c1,c2); 
  1202 		    
  1203 		Mymap::iterator it1 = c1.begin();
  1204 		CPPUNIT_ASSERT( it1->first == 'd');
  1205 		CPPUNIT_ASSERT( it1->second  == 4);
  1206 		it1++;
  1207 		CPPUNIT_ASSERT( it1->first == 'e');
  1208 		CPPUNIT_ASSERT( it1->second  == 5);
  1209 		it1++;
  1210 		CPPUNIT_ASSERT( it1->first == 'f');
  1211 		CPPUNIT_ASSERT( it1->second  == 6);
  1212 		}
  1213 		{
  1214 		typedef unordered_multimap<char, int> Mymap; 
  1215 		Mymap c1; 
  1216 		float a,b; 
  1217 		
  1218 		c1.insert(Mymap::value_type('a', 1)); 
  1219 		c1.insert(Mymap::value_type('b', 2)); 
  1220 		c1.insert(Mymap::value_type('c', 3)); 
  1221 		    
  1222 		a = (float)( (float)c1.size()/(float)c1.bucket_count() )  ;
  1223 	    b = (float)c1.load_factor();
  1224 	    CPPUNIT_ASSERT( a == b );
  1225 	    
  1226 		c1.max_load_factor(0.10f); 
  1227 		CPPUNIT_ASSERT( c1.max_load_factor() == 0.1f );
  1228 		    
  1229 		CPPUNIT_ASSERT( c1.max_bucket_count() >= c1.bucket_count() );
  1230 		c1.rehash(100); 
  1231 		}
  1232 		__UHEAP_MARKEND;
  1233 	}
  1234 void UnorderedTest::unordered_multimap_cov5()
  1235 	{
  1236 	__UHEAP_MARK;
  1237 		{
  1238 		typedef unordered_multimap<char, int> Mymap;
  1239 		Mymap c1;
  1240 		c1.max_size();
  1241 		}		
  1242 		{
  1243 		typedef unordered_multimap<char, int> Mymap; 
  1244 		Mymap c1,c2; 
  1245 		 
  1246 		c1.insert(Mymap::value_type('a', 1)); 
  1247 		c1.insert(Mymap::value_type('b', 2)); 
  1248 		c1.insert(Mymap::value_type('c', 3)); 
  1249 		    
  1250 		c2 = c1;
  1251 		Mymap::iterator it2;
  1252 	    
  1253 	    it2 = c2.begin();
  1254 	    CPPUNIT_ASSERT( it2->first == 'a');
  1255 	    CPPUNIT_ASSERT( it2->second  == 1);
  1256 		}
  1257 		{
  1258 		typedef unordered_multimap<char, int> Mymap;	
  1259 		Mymap c1; 
  1260 		 
  1261 	    c1.insert(Mymap::value_type('a', 1)); 
  1262 	    c1.insert(Mymap::value_type('b', 2)); 
  1263 	    c1.insert(Mymap::value_type('c', 3)); 
  1264 
  1265 	    Mymap c3(c1.begin(),c1.end(),8,hash<char>(),equal_to<char>(),allocator<std::pair<const char, int> >()); 
  1266 	    Mymap::iterator it1 = c3.begin();
  1267 	    CPPUNIT_ASSERT( it1->first == 'a');
  1268 	    CPPUNIT_ASSERT( it1->second  == 1);
  1269 	    it1++;
  1270 	    CPPUNIT_ASSERT( it1->first == 'b');
  1271 	    CPPUNIT_ASSERT( it1->second  == 2);
  1272 	    it1++;
  1273 	    CPPUNIT_ASSERT( it1->first == 'c');
  1274 	    CPPUNIT_ASSERT( it1->second  == 3);
  1275 
  1276 		}
  1277 		__UHEAP_MARKEND;
  1278 }
  1279 void UnorderedTest::unordered_multiset_cov1()
  1280 	{
  1281 	__UHEAP_MARK;
  1282 		{
  1283 		#if defined (STLPORT) 
  1284 		unordered_multiset<int> int_uset;
  1285 
  1286 		CPPUNIT_ASSERT( int_uset.bucket_count() < int_uset.max_bucket_count() );
  1287 
  1288 		int i;
  1289 		size_t nbBuckets = int_uset.bucket_count();
  1290 		size_t nbInserts = int_uset.bucket_count() - 1;
  1291 		for (i = 0; (size_t)i < nbInserts; ++i) {
  1292 			int_uset.insert(i);
  1293 			}
  1294 		CPPUNIT_ASSERT( nbBuckets == int_uset.bucket_count() );
  1295 
  1296 		size_t bucketSizes = 0;
  1297 		for (i = 0; (size_t)i < nbBuckets; ++i) {
  1298 			bucketSizes += int_uset.bucket_size(i);
  1299 			}
  1300 		CPPUNIT_ASSERT( bucketSizes == int_uset.size() );
  1301 		#endif
  1302 		}
  1303 		{
  1304 		#if defined (STLPORT)
  1305 		  unordered_multiset<int> int_uset;
  1306 
  1307 		  CPPUNIT_ASSERT( int_uset.max_load_factor() == 1.0f );
  1308 		  CPPUNIT_ASSERT( int_uset.load_factor() == 0.0f );
  1309 
  1310 		  size_t nbInserts = int_uset.bucket_count() - 1;
  1311 		  for (int i = 0; (size_t)i < nbInserts; ++i) {
  1312 		    int_uset.insert(i);
  1313 		  }
  1314 		  CPPUNIT_ASSERT( int_uset.size() == nbInserts );
  1315 
  1316 		  int_uset.max_load_factor(0.5f);
  1317 		  int_uset.rehash(0);
  1318 		  CPPUNIT_ASSERT( int_uset.load_factor() < int_uset.max_load_factor() );
  1319 
  1320 		  size_t bucketsHint = int_uset.bucket_count() + 1;
  1321 		  int_uset.rehash(bucketsHint);
  1322 		  CPPUNIT_ASSERT( int_uset.bucket_count() >= bucketsHint );
  1323 
  1324 		  CPPUNIT_ASSERT( int_uset.key_eq()(10, 10) );
  1325 		  CPPUNIT_ASSERT( int_uset.hash_function()(10) == 10 );
  1326 		#endif			
  1327 		}
  1328 		{
  1329 		typedef unordered_multiset<char> Myset; 
  1330 		Myset c1; 
  1331 		 
  1332 	    c1.insert('a'); 
  1333 	    c1.insert('b'); 
  1334 	    c1.insert('c'); 
  1335 	    Myset::const_iterator it = c1.begin(); 
  1336 		CPPUNIT_ASSERT(*it == 'a');
  1337 		
  1338 		Myset::const_iterator it1 = c1.end();
  1339 		
  1340 		c1.max_size();
  1341 		}
  1342 		__UHEAP_MARKEND;
  1343 	}
  1344 void UnorderedTest::unordered_multiset_cov2()
  1345 	{
  1346 	__UHEAP_MARK;
  1347 		{
  1348 		typedef unordered_multiset<char> Myset; 
  1349 		Myset c1; 
  1350 		 
  1351 	    c1.insert('a'); 
  1352 	    c1.insert('b'); 
  1353 	    c1.insert('c'); 
  1354 	    
  1355 	    c1.clear(); 
  1356 		CPPUNIT_ASSERT(c1.size() == 0 );
  1357 		}
  1358 		{
  1359 		typedef unordered_multiset<char> Myset; 
  1360 		Myset c1; 
  1361 		 
  1362 	    c1.insert('a'); 
  1363 	    c1.insert('b'); 
  1364 	    c1.insert('c');
  1365 		CPPUNIT_ASSERT( c1.erase('b')  == 1);	
  1366 		}
  1367 		{
  1368 		typedef unordered_multimap<char, int> Mymap; 
  1369 		typedef allocator<std::pair<const char, int> > Myalloc;
  1370 		Mymap c1; 
  1371 		 
  1372 	    Mymap::allocator_type al = c1.get_allocator(); 
  1373 	    CPPUNIT_ASSERT ((al == Myalloc()) == true);
  1374 		}
  1375 		{
  1376 		typedef unordered_multiset<char> Myset; 
  1377 		Myset c1,c2; 
  1378 		 
  1379 	    c1.insert('a'); 
  1380 	    c1.insert('b'); 
  1381 	    c1.insert('c'); 
  1382 	    Myset::iterator it2 = c1.insert(c1.begin(), 'd'); 
  1383 	    CPPUNIT_ASSERT(c1.size() == 4 );
  1384 	    
  1385 	    c2.insert(c1.begin(),c1.end());
  1386 	    CPPUNIT_ASSERT(c2.size() == 4 );
  1387 		}
  1388 		__UHEAP_MARKEND;
  1389 	}
  1390 void UnorderedTest::unordered_multiset_cov3()
  1391 	{
  1392 	__UHEAP_MARK;
  1393 		{
  1394 		typedef unordered_multiset<char> Myset;	
  1395 		Myset c1,c2; 
  1396 		
  1397 		
  1398 	    c1.insert('a'); 
  1399 	    c1.insert('b'); 
  1400 	    c1.insert('c'); 
  1401 
  1402 	    c2.insert('d'); 
  1403 	    c2.insert('e'); 
  1404 	    c2.insert('f'); 
  1405 	 
  1406 	    c1.swap(c2); 
  1407 	    Myset::const_iterator it1 = c1.begin(); 
  1408 		Myset::const_iterator it2 = c2.begin();
  1409 	    CPPUNIT_ASSERT( *it1 == 'd' );
  1410 	    CPPUNIT_ASSERT( *it2 == 'a' );
  1411 	    it1++;it2++;
  1412 	    CPPUNIT_ASSERT( *it1 == 'e' );
  1413 	    CPPUNIT_ASSERT( *it2 == 'b' );
  1414 	    it1++;it2++;
  1415 	    CPPUNIT_ASSERT( *it1 == 'f' );
  1416 	    CPPUNIT_ASSERT( *it2 == 'c' );
  1417 		}
  1418 		{
  1419 		typedef unordered_multiset<char> Myset;	
  1420 		Myset c1,c2; 
  1421 		
  1422 		
  1423 	    c1.insert('a'); 
  1424 	    c1.insert('b'); 
  1425 	    c1.insert('c'); 
  1426 
  1427 	    c2.insert('d'); 
  1428 	    c2.insert('e'); 
  1429 	    c2.insert('f'); 
  1430 	 
  1431 	    swap(c1,c2); 
  1432 	    Myset::const_iterator it1 = c1.begin(); 
  1433 		Myset::const_iterator it2 = c2.begin();
  1434 	    CPPUNIT_ASSERT( *it1 == 'd' );
  1435 	    CPPUNIT_ASSERT( *it2 == 'a' );
  1436 	    it1++;it2++;
  1437 	    CPPUNIT_ASSERT( *it1 == 'e' );
  1438 	    CPPUNIT_ASSERT( *it2 == 'b' );
  1439 	    it1++;it2++;
  1440 	    CPPUNIT_ASSERT( *it1 == 'f' );
  1441 	    CPPUNIT_ASSERT( *it2 == 'c' );
  1442 		}
  1443 		__UHEAP_MARKEND;
  1444 	}
  1445 void UnorderedTest::unordered_multiset_cov4()
  1446 	{
  1447 	__UHEAP_MARK;
  1448 		{
  1449 		typedef unordered_multiset<char> Myset;	
  1450 		Myset c1,c2; 	
  1451 		c1.insert('a'); 
  1452 	    c1.insert('b'); 
  1453 	    c1.insert('c'); 
  1454 	    
  1455 	    c2 = c1;
  1456 	    CPPUNIT_ASSERT(c2.size() == 3 );
  1457 		}
  1458 		{
  1459 		typedef unordered_multiset<char> Myset; 
  1460 		Myset c1; 
  1461 		 
  1462 	    c1.insert('a'); 
  1463 	    c1.insert('b'); 
  1464 	    c1.insert('c'); 
  1465 	    Myset c3(c1.begin(),c1.end(),8,hash<char>(),equal_to<char>(),allocator<pair<const char, int> >()); 
  1466 	    
  1467 	    Myset::iterator it1 = c3.begin();
  1468 	    CPPUNIT_ASSERT( *it1 == 'a');
  1469 	    it1++;
  1470 	    CPPUNIT_ASSERT( *it1 == 'b');
  1471 	    it1++;
  1472 	    CPPUNIT_ASSERT( *it1 == 'c');
  1473 		}
  1474 		__UHEAP_MARKEND;
  1475 }