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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 //Has to be first for StackAllocator swap overload to be taken
17 //into account (at least using GCC 4.0.1)
18 #include "stack_allocator.h"
24 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
32 #include "cppunit/cppunit_proxy.h"
40 #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
47 class HashTest : public CPPUNIT_NS::TestCase
49 CPPUNIT_TEST_SUITE(HashTest);
50 #if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
57 CPPUNIT_TEST(insert_erase);
58 CPPUNIT_TEST(allocator_with_state);
59 CPPUNIT_TEST(hash_map_cov1);
60 CPPUNIT_TEST(hash_map_cov2);
61 CPPUNIT_TEST(hash_map_cov3);
62 CPPUNIT_TEST(hash_map_cov4);
63 CPPUNIT_TEST(hash_map_cov5);
64 CPPUNIT_TEST(hash_map_cov6);
65 CPPUNIT_TEST(hash_multimap_cov1);
66 CPPUNIT_TEST(hash_multimap_cov2);
67 CPPUNIT_TEST(hash_multimap_cov3);
68 CPPUNIT_TEST(hash_set_cov1);
69 CPPUNIT_TEST(hash_set_cov2);
70 CPPUNIT_TEST(hash_set_cov3);
71 CPPUNIT_TEST(hash_set_cov4);
72 CPPUNIT_TEST(hash_set_cov5);
73 CPPUNIT_TEST(hash_set_cov6);
74 CPPUNIT_TEST(hash_multiset_cov1);
75 CPPUNIT_TEST(hash_multiset_cov2);
76 CPPUNIT_TEST(hash_multiset_cov3);
77 //CPPUNIT_TEST(equality);
78 CPPUNIT_TEST_SUITE_END();
80 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
81 typedef hash_multiset<char, hash<char>, equal_to<char> > hmset;
96 void hash_multimap_cov1();
97 void hash_multimap_cov2();
98 void hash_multimap_cov3();
100 void hash_set_cov2();
101 void hash_set_cov3();
102 void hash_set_cov4();
103 void hash_set_cov5();
104 void hash_set_cov6();
105 void hash_multiset_cov1();
106 void hash_multiset_cov2();
107 void hash_multiset_cov3();
109 void allocator_with_state();
112 CPPUNIT_TEST_SUITE_REGISTRATION(HashTest);
115 // tests implementation
117 void HashTest::hmap1()
119 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
120 typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
122 // Store mappings between roman numerals and decimals.
124 m['x'] = "20"; // Deliberate mistake.
127 CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"20") );
128 m['x'] = "10"; // Correct mistake.
129 CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"10") );
131 CPPUNIT_ASSERT( !strcmp(m['z'].c_str(),"") );
133 CPPUNIT_ASSERT( m.count('z')==1 );
134 pair<maptype::iterator, bool> p = m.insert(pair<const char, crope>('c', crope("100")));
136 CPPUNIT_ASSERT(p.second);
138 p = m.insert(pair<const char, crope>('c', crope("100")));
139 CPPUNIT_ASSERT(!p.second);
141 //Some iterators compare check, really compile time checks
142 maptype::iterator ite(m.begin());
143 maptype::const_iterator cite(m.begin());
145 maptype const& cm = m;
147 CPPUNIT_ASSERT( ite == cite );
148 CPPUNIT_ASSERT( !(ite != cite) );
149 CPPUNIT_ASSERT( cite == ite );
150 CPPUNIT_ASSERT( !(cite != ite) );
154 void HashTest::hmmap1()
156 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
157 typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap;
159 CPPUNIT_ASSERT(m.count('X')==0);
160 m.insert(pair<const char,int>('X', 10)); // Standard way.
161 CPPUNIT_ASSERT(m.count('X')==1);
162 // m.insert('X', 20); // Non-standard, but very convenient!
163 m.insert(pair<const char,int>('X', 20)); // jbuck: standard way
164 CPPUNIT_ASSERT(m.count('X')==2);
165 // m.insert('Y', 32);
166 m.insert(pair<const char,int>('Y', 32)); // jbuck: standard way
167 mmap::iterator i = m.find('X'); // Find first match.
169 CPPUNIT_ASSERT((*i).first=='X');
170 CPPUNIT_ASSERT((*i).second==10);
172 CPPUNIT_ASSERT((*i).first=='X');
173 CPPUNIT_ASSERT((*i).second==20);
175 CPPUNIT_ASSERT((*i).first=='Y');
176 CPPUNIT_ASSERT((*i).second==32);
178 CPPUNIT_ASSERT(i==m.end());
180 size_t count = m.erase('X');
181 CPPUNIT_ASSERT(count==2);
183 //Some iterators compare check, really compile time checks
184 mmap::iterator ite(m.begin());
185 mmap::const_iterator cite(m.begin());
186 CPPUNIT_ASSERT( ite == cite );
187 CPPUNIT_ASSERT( !(ite != cite) );
188 CPPUNIT_ASSERT( cite == ite );
189 CPPUNIT_ASSERT( !(cite != ite) );
191 typedef hash_multimap<size_t, size_t> HMapType;
194 //We fill the map to implicitely start a rehash.
195 for (size_t counter = 0; counter < 3077; ++counter)
196 hmap.insert(HMapType::value_type(1, counter));
198 hmap.insert(HMapType::value_type(12325, 1));
199 hmap.insert(HMapType::value_type(12325, 2));
201 CPPUNIT_ASSERT( hmap.count(12325) == 2 );
203 //At this point 23 goes to the same bucket as 12325, it used to reveal a bug.
204 hmap.insert(HMapType::value_type(23, 0));
206 CPPUNIT_ASSERT( hmap.count(12325) == 2 );
210 void HashTest::hmset1()
212 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
214 CPPUNIT_ASSERT( s.count(star) == 0 );
216 CPPUNIT_ASSERT( s.count(star) == 1 );
218 CPPUNIT_ASSERT( s.count(star) == 2 );
219 hmset::iterator i = s.find(char(40));
220 CPPUNIT_ASSERT( i == s.end() );
223 CPPUNIT_ASSERT( i != s.end() )
224 CPPUNIT_ASSERT( *i == '*' );
225 CPPUNIT_ASSERT( s.erase(star) == 2 );
228 void HashTest::hset2()
230 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
231 hash_set<int, hash<int>, equal_to<int> > s;
232 pair<hash_set<int, hash<int>, equal_to<int> >::iterator, bool> p = s.insert(42);
233 CPPUNIT_ASSERT( p.second );
234 CPPUNIT_ASSERT( *(p.first) == 42 );
237 CPPUNIT_ASSERT( !p.second );
241 void HashTest::insert_erase()
243 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
244 typedef hash_map<string, size_t, hash<string>, equal_to<string> > hmap;
245 typedef hmap::value_type val_type;
248 CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
249 CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
250 CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
252 CPPUNIT_ASSERT( values.erase("foo") == 1 );
253 CPPUNIT_ASSERT( values.erase("bar") == 1 );
254 CPPUNIT_ASSERT( values.erase("abc") == 1 );
259 CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
260 CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
261 CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
263 CPPUNIT_ASSERT( values.erase("abc") == 1 );
264 CPPUNIT_ASSERT( values.erase("bar") == 1 );
265 CPPUNIT_ASSERT( values.erase("foo") == 1 );
271 * Here is the test showing why equality operator on hash containers
274 struct equality_hash_func {
275 size_t operator () (size_t val) const {
280 void HashTest::equality()
282 hash_set<size_t, equality_hash_func, equal_to<size_t> > s1, s2;
290 //s1 and s2 contains both 10 and 20:
291 CPPUNIT_ASSERT( s1 == s2 );
295 void HashTest::allocator_with_state()
297 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
299 StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
302 StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
305 typedef hash_set<int, hash<int>, equal_to<int>, StackAllocator<int> > HashSetInt;
306 HashSetInt hint1(10, hash<int>(), equal_to<int>(), stack1);
309 for (i = 0; i < 5; ++i)
311 HashSetInt hint1Cpy(hint1);
313 HashSetInt hint2(10, hash<int>(), equal_to<int>(), stack2);
316 HashSetInt hint2Cpy(hint2);
320 CPPUNIT_ASSERT( hint1.get_allocator().swaped() );
321 CPPUNIT_ASSERT( hint2.get_allocator().swaped() );
323 CPPUNIT_ASSERT( hint1.get_allocator() == stack2 );
324 CPPUNIT_ASSERT( hint2.get_allocator() == stack1 );
326 CPPUNIT_ASSERT( stack1.ok() );
327 CPPUNIT_ASSERT( stack2.ok() );
330 void HashTest::hash_map_cov1()
334 hash_map <int, int> hm1, hm2;
335 hash_map <int, int>::iterator hm1_Iter;
336 hash_map <int, int>::const_iterator hm1_cIter;
337 typedef pair <int, int> Int_Pair;
339 hm1.insert ( Int_Pair ( 1, 10 ) );
340 hm1.insert ( Int_Pair ( 2, 20 ) );
341 hm1.insert ( Int_Pair ( 3, 30 ) );
342 hm2.insert ( Int_Pair ( 30, 300 ) );
345 hm1_Iter = hm1.begin( );
346 CPPUNIT_ASSERT( hm1_Iter -> second == 300);
347 hm1_Iter = hm1.end( );
349 hm1_cIter = hm1.end( );
351 CPPUNIT_ASSERT( hm1.size() == 0 );
352 CPPUNIT_ASSERT( hm1.empty() == true );
355 hash_map <int, int> hm1, hm2;
356 hash_map <int, int>::iterator hm1_Iter;
357 hash_map <int, int>::const_iterator hm1_cIter;
358 typedef pair <int, int> Int_Pair;
360 hm1.insert ( Int_Pair ( 1, 10 ) );
361 hm1.insert ( Int_Pair ( 2, 20 ) );
362 hm1.insert ( Int_Pair ( 3, 30 ) );
363 hm2.insert ( Int_Pair ( 30, 300 ) );
366 hm1_Iter = hm1.begin( );
367 CPPUNIT_ASSERT( hm1_Iter -> second == 300);
368 hm1_Iter = hm1.end( );
370 hm1_cIter = hm1.end( );
372 CPPUNIT_ASSERT( hm1.size() == 0 );
373 CPPUNIT_ASSERT( hm1.empty() == true );
377 void HashTest::hash_map_cov2()
381 hash_map <int, int> hm1;
383 typedef pair <int, int> Int_Pair;
385 hm1.insert ( Int_Pair ( 1, 1 ) );
387 CPPUNIT_ASSERT( i == 1);
389 i = hm1.max_size(); // for covering the api
391 hm1.insert ( Int_Pair ( 2, 4 ) );
393 CPPUNIT_ASSERT( i == 2);
395 bcount = hm1.bucket_count();
396 CPPUNIT_ASSERT( bcount >= 10);
397 hm1.elems_in_bucket(1);
400 typedef hash_multimap<int, int> mmap;
403 typedef pair <int, int> Int_Pair;
404 m.insert ( Int_Pair ( 1, 10 ) );
405 m.insert ( Int_Pair ( 2, 20 ) );
406 m.insert ( Int_Pair ( 3, 30 ) );
408 std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
409 CPPUNIT_ASSERT( pair1.first->first == 2);
410 CPPUNIT_ASSERT( pair1.first->second == 20);
411 std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
412 CPPUNIT_ASSERT( pair2.first->first == 1);
413 CPPUNIT_ASSERT( pair2.first->second == 10);
416 typedef hash_multimap<int, int> mmap;
419 typedef pair <int, int> Int_Pair;
420 m.insert ( Int_Pair ( 1, 10 ) );
421 m.insert ( Int_Pair ( 2, 20 ) );
422 m.insert ( Int_Pair ( 3, 30 ) );
425 mmap::iterator i1 = m.begin();
426 CPPUNIT_ASSERT( i1 -> second == 20);
427 CPPUNIT_ASSERT( m.size() == 2 );
428 m.erase(m.begin(),m.end());
429 CPPUNIT_ASSERT( m.size() == 0 );
433 void HashTest::hash_map_cov3()
437 typedef hash_multimap<int, int> mmap;
440 typedef pair <int, int> Int_Pair;
441 m.insert ( Int_Pair ( 1, 10 ) );
442 m.insert ( Int_Pair ( 2, 20 ) );
443 m.insert ( Int_Pair ( 3, 30 ) );
445 mmap::iterator i1 = m.find(1);
446 CPPUNIT_ASSERT( i1 -> second == 10);
447 mmap::const_iterator i2 = m.find(3);
448 CPPUNIT_ASSERT( i2 -> second == 30);
450 // negative test case where the element to find is not present in the
451 // hash , so it returns the successive element of the last element.
452 mmap::iterator i3 = m.find(4);
453 mmap::iterator i4 = m.end();
454 CPPUNIT_ASSERT( i3 == i4);
457 typedef hash_multimap<int, int> mmap;
458 typedef allocator<std::pair<int, int> > Myalloc;
461 mmap::allocator_type al = m.get_allocator();
462 CPPUNIT_ASSERT ((al == Myalloc()) == true);
464 mmap::hasher hfn = m.hash_funct(); // returns the hasher function
467 typedef hash_multimap<int, int> mmap;
470 typedef pair <int, int> Int_Pair;
471 m1.insert ( Int_Pair ( 1, 10 ) );
472 m1.insert ( Int_Pair ( 2, 20 ) );
473 m1.insert ( Int_Pair ( 3, 30 ) );
475 m2.insert ( m1.begin(),m1.end());
476 mmap::iterator i1 = m2.begin();
477 CPPUNIT_ASSERT( i1 -> second == 10);
481 void HashTest::hash_map_cov4()
485 typedef hash_map<int, int> mmap;
487 typedef pair <int, int> Int_Pair;
488 m.insert ( Int_Pair ( 1, 10 ) );
489 m.insert ( Int_Pair ( 2, 20 ) );
490 m.insert ( Int_Pair ( 3, 30 ) );
492 std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
493 CPPUNIT_ASSERT( pair1.first->first == 2);
494 CPPUNIT_ASSERT( pair1.first->second == 20);
495 std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
496 CPPUNIT_ASSERT( pair2.first->first == 1);
497 CPPUNIT_ASSERT( pair2.first->second == 10);
500 typedef hash_map<int, int> mmap;
502 typedef pair <int, int> Int_Pair;
503 m.insert ( Int_Pair ( 1, 10 ) );
504 m.insert ( Int_Pair ( 2, 20 ) );
505 m.insert ( Int_Pair ( 3, 30 ) );
508 mmap::iterator i1 = m.begin();
509 CPPUNIT_ASSERT( i1 -> second == 20);
510 CPPUNIT_ASSERT( m.size() == 2 );
511 m.erase(m.begin(),m.end());
512 CPPUNIT_ASSERT( m.size() == 0 );
515 typedef hash_map<int, int> mmap;
518 typedef pair <int, int> Int_Pair;
519 m.insert ( Int_Pair ( 1, 10 ) );
520 m.insert ( Int_Pair ( 2, 20 ) );
521 m.insert ( Int_Pair ( 3, 30 ) );
523 mmap::iterator i1 = m.find(1);
524 CPPUNIT_ASSERT( i1 -> second == 10);
525 mmap::const_iterator i2 = m.find(3);
526 CPPUNIT_ASSERT( i2 -> second == 30);
530 void HashTest::hash_map_cov5()
534 typedef hash_map<int, int> mmap;
535 typedef allocator<std::pair<int, int> > Myalloc;
537 mmap::allocator_type al = m.get_allocator();
538 CPPUNIT_ASSERT ((al == Myalloc()) == true);
540 mmap::hasher hfn = m.hash_funct(); // returns the hasher function
543 typedef hash_map<int, int> mmap;
546 typedef pair <int, int> Int_Pair;
547 m1.insert ( Int_Pair ( 1, 10 ) );
548 m1.insert ( Int_Pair ( 2, 20 ) );
549 m1.insert ( Int_Pair ( 3, 30 ) );
551 m2.insert ( m1.begin(),m1.end());
552 mmap::iterator i1 = m2.begin();
553 CPPUNIT_ASSERT( i1 -> second == 10);
556 typedef hash_map<char, int> mmap;
558 mmap::key_equal cmpfn = c1.key_eq();
559 CPPUNIT_ASSERT( cmpfn('a','a') == true);
561 c1.max_bucket_count(); // for covering the api
564 typedef hash_map<int, int> mmap;
566 typedef pair <int, int> Int_Pair;
567 m1.insert_noresize ( Int_Pair ( 1, 10 ) );
568 m1.insert_noresize ( Int_Pair ( 2, 20 ) );
569 m1.insert_noresize ( Int_Pair ( 3, 30 ) );
571 mmap::iterator i1 = m1.begin();
572 CPPUNIT_ASSERT( i1 -> second == 10);
576 void HashTest::hash_map_cov6()
580 typedef hash_map<int, int> mmap;
584 typedef pair <int, int> Int_Pair;
585 m1.insert ( Int_Pair ( 1, 10 ) );
586 m1.insert ( Int_Pair ( 2, 20 ) );
587 m1.insert ( Int_Pair ( 3, 30 ) );
590 mmap::iterator i1 = m2.begin();
591 CPPUNIT_ASSERT( i1 -> second == 10);
594 bcount = m3.bucket_count();
595 CPPUNIT_ASSERT( bcount >= 10);
597 mmap::hasher hfn = m1.hash_funct();
599 bcount = m4.bucket_count();
600 CPPUNIT_ASSERT( bcount >= 20);
602 mmap m5(m1.begin(),m2.end());
603 CPPUNIT_ASSERT( m5.size() == 3);
605 mmap m6(m1.begin(),m2.end(),30);
606 CPPUNIT_ASSERT( m6.size() == 3);
607 bcount = m6.bucket_count();
608 CPPUNIT_ASSERT( bcount >= 30);
610 mmap m7(m1.begin(),m2.end(),30,hfn);
611 CPPUNIT_ASSERT( m7.size() == 3);
612 bcount = m7.bucket_count();
613 CPPUNIT_ASSERT( bcount >= 30);
615 mmap::key_equal cmpfn;// = c1.key_eq();
616 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
618 mmap m9(30,hfn,cmpfn);
623 void HashTest::hash_multimap_cov1()
627 hash_multimap <int, int> hm1, hm2;
628 hash_multimap <int, int>::iterator hm1_Iter;
629 hash_multimap <int, int>::const_iterator hm1_cIter;
630 typedef pair <int, int> Int_Pair;
632 hm1.insert ( Int_Pair ( 1, 10 ) );
633 hm1.insert ( Int_Pair ( 2, 20 ) );
634 hm1.insert ( Int_Pair ( 3, 30 ) );
635 hm2.insert ( Int_Pair ( 30, 300 ) );
638 hm1_Iter = hm1.begin( );
639 CPPUNIT_ASSERT( hm1_Iter -> second == 300);
640 hm1_Iter = hm1.end( );
641 hm1_cIter = hm1.end( );
643 CPPUNIT_ASSERT( hm1.size() == 0 );
644 CPPUNIT_ASSERT( hm1.empty() == true );
647 hash_multimap <int, int> hm1, hm2;
648 hash_multimap <int, int>::iterator hm1_Iter;
649 hash_multimap <int, int>::const_iterator hm1_cIter;
650 typedef pair <int, int> Int_Pair;
652 hm1.insert ( Int_Pair ( 1, 10 ) );
653 hm1.insert ( Int_Pair ( 2, 20 ) );
654 hm1.insert ( Int_Pair ( 3, 30 ) );
655 hm2.insert ( Int_Pair ( 30, 300 ) );
658 hm1_Iter = hm1.begin( );
659 CPPUNIT_ASSERT( hm1_Iter -> second == 300);
660 hm1_Iter = hm1.end( );
661 hm1_cIter = hm1.end( );
663 CPPUNIT_ASSERT( hm1.size() == 0 );
664 CPPUNIT_ASSERT( hm1.empty() == true );
668 void HashTest::hash_multimap_cov2()
672 hash_multimap <int, int> hm1;
674 typedef pair <int, int> Int_Pair;
676 hm1.insert ( Int_Pair ( 1, 1 ) );
678 CPPUNIT_ASSERT( i == 1);
680 i = hm1.max_size(); // for covering the api
682 hm1.insert ( Int_Pair ( 2, 4 ) );
684 CPPUNIT_ASSERT( i == 2);
686 bcount = hm1.bucket_count();
687 CPPUNIT_ASSERT( bcount >= 10);
688 hm1.elems_in_bucket(1);
691 typedef hash_multimap<int, int> mmap;
694 typedef pair <int, int> Int_Pair;
695 m1.insert_noresize ( Int_Pair ( 1, 10 ) );
696 m1.insert_noresize ( Int_Pair ( 2, 20 ) );
697 m1.insert_noresize ( Int_Pair ( 3, 30 ) );
699 mmap::iterator i1 = m1.begin();
700 CPPUNIT_ASSERT( i1 -> second == 10);
703 typedef hash_multimap<char, int> mmap;
705 mmap::key_equal cmpfn = c1.key_eq();
706 CPPUNIT_ASSERT( cmpfn('a','a') == true);
708 c1.max_bucket_count(); // for covering the api
712 void HashTest::hash_multimap_cov3()
716 typedef hash_multimap<int, int> mmap;
720 typedef pair <int, int> Int_Pair;
721 m1.insert ( Int_Pair ( 1, 10 ) );
722 m1.insert ( Int_Pair ( 2, 20 ) );
723 m1.insert ( Int_Pair ( 3, 30 ) );
726 mmap::iterator i1 = m2.begin();
727 CPPUNIT_ASSERT( i1 -> second == 10);
730 bcount = m3.bucket_count();
731 CPPUNIT_ASSERT( bcount >= 10);
733 mmap::hasher hfn = m1.hash_funct();
735 bcount = m4.bucket_count();
736 CPPUNIT_ASSERT( bcount >= 20);
738 mmap m5(m1.begin(),m2.end());
739 CPPUNIT_ASSERT( m5.size() == 3);
741 mmap m6(m1.begin(),m2.end(),30);
742 CPPUNIT_ASSERT( m6.size() == 3);
743 bcount = m6.bucket_count();
744 CPPUNIT_ASSERT( bcount >= 30);
746 mmap m7(m1.begin(),m2.end(),30,hfn);
747 CPPUNIT_ASSERT( m7.size() == 3);
748 bcount = m7.bucket_count();
749 CPPUNIT_ASSERT( bcount >= 30);
751 mmap::key_equal cmpfn;
752 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
754 mmap m9(30,hfn,cmpfn);
759 void HashTest::hash_set_cov1()
763 hash_set <int> hm1, hm2;
764 hash_set <int>::iterator hm1_Iter;
765 hash_set <int>::const_iterator hm1_cIter;
773 hm1_Iter = hm1.begin( );
774 CPPUNIT_ASSERT( *hm1_Iter == 300);
775 hm1_Iter = hm1.end( );
776 hm1_cIter = hm1.end( );
778 CPPUNIT_ASSERT( hm1.size() == 0 );
779 CPPUNIT_ASSERT( hm1.empty() == true );
782 hash_set <int> hm1, hm2;
783 hash_set <int>::iterator hm1_Iter;
784 hash_set <int>::const_iterator hm1_cIter;
792 hm1_Iter = hm1.begin( );
793 CPPUNIT_ASSERT( *hm1_Iter == 300);
794 hm1_Iter = hm1.end( );
795 hm1_cIter = hm1.end( );
797 CPPUNIT_ASSERT( hm1.size() == 0 );
798 CPPUNIT_ASSERT( hm1.empty() == true );
802 void HashTest::hash_set_cov2()
811 CPPUNIT_ASSERT( i == 1);
813 i = hm1.max_size(); // for covering the api
817 CPPUNIT_ASSERT( i == 2);
819 bcount = hm1.bucket_count();
820 CPPUNIT_ASSERT( bcount >= 10);
821 hm1.elems_in_bucket(1);
824 typedef hash_multiset<int> mmap;
831 std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
832 CPPUNIT_ASSERT( *(pair1.first) == 20);
833 CPPUNIT_ASSERT( *(pair1.second) == 30);
834 // negative test case for equal_range where the key value is not present.
835 std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
836 CPPUNIT_ASSERT( pair2.first == m.end());
837 CPPUNIT_ASSERT( pair2.second == m.end());
840 typedef hash_multiset<int> mmap;
848 mmap::iterator i1 = m.begin();
849 CPPUNIT_ASSERT( *i1 == 20);
850 CPPUNIT_ASSERT( m.size() == 2 );
851 m.erase(m.begin(),m.end());
852 CPPUNIT_ASSERT( m.size() == 0 );
856 void HashTest::hash_set_cov3()
860 typedef hash_multiset<int> mmap;
867 mmap::iterator i1 = m.find(10);
868 CPPUNIT_ASSERT( *i1 == 10);
869 mmap::const_iterator i2 = m.find(30);
870 CPPUNIT_ASSERT( *i2 == 30);
873 typedef hash_multiset<int> mmap;
874 typedef allocator<std::pair<int, int> > Myalloc;
877 mmap::allocator_type al = m.get_allocator();
878 CPPUNIT_ASSERT ((al == Myalloc()) == true);
880 mmap::hasher hfn = m.hash_funct(); // returns the hasher function
883 typedef hash_multiset<int> mmap;
890 m2.insert ( m1.begin(),m1.end());
891 mmap::iterator i1 = m2.begin();
892 CPPUNIT_ASSERT( *i1 == 10);
896 typedef hash_set<int> mmap;
903 std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
904 CPPUNIT_ASSERT( *(pair1.first) == 20);
905 CPPUNIT_ASSERT( *(pair1.second) == 30);
906 // negative test case for equal_range where the key value is not present.
907 std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
908 CPPUNIT_ASSERT( pair2.first == m.end());
909 CPPUNIT_ASSERT( pair2.second == m.end()); }
912 void HashTest::hash_set_cov4()
916 typedef hash_set<int> mmap;
924 mmap::iterator i1 = m.begin();
925 CPPUNIT_ASSERT( *i1 == 20);
926 CPPUNIT_ASSERT( m.size() == 2 );
927 m.erase(m.begin(),m.end());
928 CPPUNIT_ASSERT( m.size() == 0 );
931 typedef hash_set<int> mmap;
938 mmap::iterator i1 = m.find(10);
939 CPPUNIT_ASSERT( *i1 == 10);
940 mmap::const_iterator i2 = m.find(30);
941 CPPUNIT_ASSERT( *i2 == 30);
944 typedef hash_set<int> mmap;
945 typedef allocator<std::pair<int, int> > Myalloc;
948 mmap::allocator_type al = m.get_allocator();
949 CPPUNIT_ASSERT ((al == Myalloc()) == true);
951 mmap::hasher hfn = m.hash_funct(); // returns the hasher function
955 void HashTest::hash_set_cov5()
959 typedef hash_set<int> mmap;
966 m2.insert ( m1.begin(),m1.end());
967 mmap::iterator i1 = m2.begin();
968 CPPUNIT_ASSERT( *i1 == 10);
971 typedef hash_set<char> mmap;
973 mmap::key_equal cmpfn = c1.key_eq();
974 CPPUNIT_ASSERT( cmpfn('a','a') == true);
976 c1.max_bucket_count(); // for covering the api
979 typedef hash_set<int> mmap;
982 m1.insert_noresize ( 10 );
983 m1.insert_noresize ( 20 );
984 m1.insert_noresize ( 30 );
986 mmap::iterator i1 = m1.begin();
987 CPPUNIT_ASSERT( *i1 == 10);
990 typedef hash_set<int> mmap;
999 mmap::iterator i1 = m2.begin();
1000 CPPUNIT_ASSERT( *i1 == 10);
1003 bcount = m3.bucket_count();
1004 CPPUNIT_ASSERT( bcount >= 10);
1006 mmap::hasher hfn = m1.hash_funct();
1008 bcount = m4.bucket_count();
1009 CPPUNIT_ASSERT( bcount >= 20);
1011 mmap m5(m1.begin(),m2.end());
1012 CPPUNIT_ASSERT( m5.size() == 3);
1014 mmap m6(m1.begin(),m2.end(),30);
1015 CPPUNIT_ASSERT( m6.size() == 3);
1016 bcount = m6.bucket_count();
1017 CPPUNIT_ASSERT( bcount >= 30);
1019 mmap m7(m1.begin(),m2.end(),30,hfn);
1020 CPPUNIT_ASSERT( m7.size() == 3);
1021 bcount = m7.bucket_count();
1022 CPPUNIT_ASSERT( bcount >= 30);
1024 mmap::key_equal cmpfn;// = c1.key_eq();
1025 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1027 mmap m9(30,hfn,cmpfn);
1031 void HashTest::hash_set_cov6()
1035 typedef hash_set<int> mmap;
1042 CPPUNIT_ASSERT( m1.count(10) == 1);
1043 CPPUNIT_ASSERT( m1.erase(10) == 1);
1044 CPPUNIT_ASSERT( m1.count(10) == 0);
1048 hash_set <int>::iterator hm1_Iter;
1052 hm1_Iter = hm1.begin( );
1053 CPPUNIT_ASSERT( *hm1_Iter == 10);
1055 CPPUNIT_ASSERT( *hm1_Iter == 20);
1057 CPPUNIT_ASSERT( *hm1_Iter == 30);
1063 void HashTest::hash_multiset_cov1()
1067 hash_multiset <int> hm1, hm2;
1068 hash_multiset <int>::iterator hm1_Iter;
1069 hash_multiset <int>::const_iterator hm1_cIter;
1077 hm1_Iter = hm1.begin( );
1078 CPPUNIT_ASSERT( *hm1_Iter== 300);
1079 hm1_Iter = hm1.end( );
1080 hm1_cIter = hm1.end( );
1082 CPPUNIT_ASSERT( hm1.size() == 0 );
1083 CPPUNIT_ASSERT( hm1.empty() == true );
1086 hash_multiset <int> hm1, hm2;
1087 hash_multiset <int>::iterator hm1_Iter;
1088 hash_multiset <int>::const_iterator hm1_cIter;
1096 hm1_Iter = hm1.begin( );
1097 CPPUNIT_ASSERT( *hm1_Iter== 300);
1098 hm1_Iter = hm1.end( );
1099 hm1_cIter = hm1.end( );
1101 CPPUNIT_ASSERT( hm1.size() == 0 );
1102 CPPUNIT_ASSERT( hm1.empty() == true );
1106 void HashTest::hash_multiset_cov2()
1110 hash_multiset <int> hm1;
1115 CPPUNIT_ASSERT( i == 1);
1117 i = hm1.max_size(); // for covering the api
1121 CPPUNIT_ASSERT( i == 2);
1123 bcount = hm1.bucket_count();
1124 CPPUNIT_ASSERT( bcount >= 10);
1125 hm1.elems_in_bucket(1);
1128 typedef hash_multiset<int> mmap;
1131 m1.insert_noresize ( 10 );
1132 m1.insert_noresize ( 20 );
1133 m1.insert_noresize ( 30 );
1135 mmap::iterator i1 = m1.begin();
1136 CPPUNIT_ASSERT( *i1 == 10);
1139 typedef hash_multiset<char> mmap;
1141 mmap::key_equal cmpfn = c1.key_eq();
1142 CPPUNIT_ASSERT( cmpfn('a','a') == true);
1144 c1.max_bucket_count(); // for covering the api
1148 void HashTest::hash_multiset_cov3()
1152 typedef hash_multiset<int> mmap;
1161 mmap::iterator i1 = m2.begin();
1162 CPPUNIT_ASSERT( *i1 == 10);
1165 bcount = m3.bucket_count();
1166 CPPUNIT_ASSERT( bcount >= 10);
1168 mmap::hasher hfn = m1.hash_funct();
1170 bcount = m4.bucket_count();
1171 CPPUNIT_ASSERT( bcount >= 20);
1173 mmap m5(m1.begin(),m2.end());
1174 CPPUNIT_ASSERT( m5.size() == 3);
1176 mmap m6(m1.begin(),m2.end(),30);
1177 CPPUNIT_ASSERT( m6.size() == 3);
1178 bcount = m6.bucket_count();
1179 CPPUNIT_ASSERT( bcount >= 30);
1181 mmap m7(m1.begin(),m2.end(),30,hfn);
1182 CPPUNIT_ASSERT( m7.size() == 3);
1183 bcount = m7.bucket_count();
1184 CPPUNIT_ASSERT( bcount >= 30);
1186 mmap::key_equal cmpfn;// = c1.key_eq();
1187 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
1189 mmap m9(30,hfn,cmpfn);