|
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 //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" |
|
19 |
|
20 #include <vector> |
|
21 #include <algorithm> |
|
22 #include <e32std.h> |
|
23 |
|
24 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
25 # include <hash_map> |
|
26 # include <hash_set> |
|
27 # include <rope> |
|
28 # endif |
|
29 |
|
30 #include <string> |
|
31 |
|
32 #include "cppunit/cppunit_proxy.h" |
|
33 |
|
34 #if defined (__MVS__) |
|
35 const char star = 92; |
|
36 #else |
|
37 const char star = 42; |
|
38 #endif |
|
39 |
|
40 #if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES) |
|
41 using namespace std; |
|
42 #endif |
|
43 |
|
44 // |
|
45 // TestCase class |
|
46 // |
|
47 class HashTest : public CPPUNIT_NS::TestCase |
|
48 { |
|
49 CPPUNIT_TEST_SUITE(HashTest); |
|
50 #if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS) |
|
51 CPPUNIT_IGNORE; |
|
52 #endif |
|
53 CPPUNIT_TEST(hmap1); |
|
54 CPPUNIT_TEST(hmmap1); |
|
55 CPPUNIT_TEST(hmset1); |
|
56 CPPUNIT_TEST(hset2); |
|
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(); |
|
79 |
|
80 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
81 typedef hash_multiset<char, hash<char>, equal_to<char> > hmset; |
|
82 #endif |
|
83 |
|
84 protected: |
|
85 void hmap1(); |
|
86 void hmmap1(); |
|
87 void hmset1(); |
|
88 void hset2(); |
|
89 void insert_erase(); |
|
90 void hash_map_cov1(); |
|
91 void hash_map_cov2(); |
|
92 void hash_map_cov3(); |
|
93 void hash_map_cov4(); |
|
94 void hash_map_cov5(); |
|
95 void hash_map_cov6(); |
|
96 void hash_multimap_cov1(); |
|
97 void hash_multimap_cov2(); |
|
98 void hash_multimap_cov3(); |
|
99 void hash_set_cov1(); |
|
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(); |
|
108 //void equality(); |
|
109 void allocator_with_state(); |
|
110 }; |
|
111 |
|
112 CPPUNIT_TEST_SUITE_REGISTRATION(HashTest); |
|
113 |
|
114 // |
|
115 // tests implementation |
|
116 // |
|
117 void HashTest::hmap1() |
|
118 { |
|
119 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
120 typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype; |
|
121 maptype m; |
|
122 // Store mappings between roman numerals and decimals. |
|
123 m['l'] = "50"; |
|
124 m['x'] = "20"; // Deliberate mistake. |
|
125 m['v'] = "5"; |
|
126 m['i'] = "1"; |
|
127 CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"20") ); |
|
128 m['x'] = "10"; // Correct mistake. |
|
129 CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"10") ); |
|
130 |
|
131 CPPUNIT_ASSERT( !strcmp(m['z'].c_str(),"") ); |
|
132 |
|
133 CPPUNIT_ASSERT( m.count('z')==1 ); |
|
134 pair<maptype::iterator, bool> p = m.insert(pair<const char, crope>('c', crope("100"))); |
|
135 |
|
136 CPPUNIT_ASSERT(p.second); |
|
137 |
|
138 p = m.insert(pair<const char, crope>('c', crope("100"))); |
|
139 CPPUNIT_ASSERT(!p.second); |
|
140 |
|
141 //Some iterators compare check, really compile time checks |
|
142 maptype::iterator ite(m.begin()); |
|
143 maptype::const_iterator cite(m.begin()); |
|
144 cite = m.begin(); |
|
145 maptype const& cm = m; |
|
146 cite = cm.begin(); |
|
147 CPPUNIT_ASSERT( ite == cite ); |
|
148 CPPUNIT_ASSERT( !(ite != cite) ); |
|
149 CPPUNIT_ASSERT( cite == ite ); |
|
150 CPPUNIT_ASSERT( !(cite != ite) ); |
|
151 #endif |
|
152 } |
|
153 |
|
154 void HashTest::hmmap1() |
|
155 { |
|
156 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
157 typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap; |
|
158 mmap m; |
|
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. |
|
168 |
|
169 CPPUNIT_ASSERT((*i).first=='X'); |
|
170 CPPUNIT_ASSERT((*i).second==10); |
|
171 i++; |
|
172 CPPUNIT_ASSERT((*i).first=='X'); |
|
173 CPPUNIT_ASSERT((*i).second==20); |
|
174 i++; |
|
175 CPPUNIT_ASSERT((*i).first=='Y'); |
|
176 CPPUNIT_ASSERT((*i).second==32); |
|
177 i++; |
|
178 CPPUNIT_ASSERT(i==m.end()); |
|
179 |
|
180 size_t count = m.erase('X'); |
|
181 CPPUNIT_ASSERT(count==2); |
|
182 |
|
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) ); |
|
190 |
|
191 typedef hash_multimap<size_t, size_t> HMapType; |
|
192 HMapType hmap; |
|
193 |
|
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)); |
|
197 |
|
198 hmap.insert(HMapType::value_type(12325, 1)); |
|
199 hmap.insert(HMapType::value_type(12325, 2)); |
|
200 |
|
201 CPPUNIT_ASSERT( hmap.count(12325) == 2 ); |
|
202 |
|
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)); |
|
205 |
|
206 CPPUNIT_ASSERT( hmap.count(12325) == 2 ); |
|
207 #endif |
|
208 } |
|
209 |
|
210 void HashTest::hmset1() |
|
211 { |
|
212 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
213 hmset s; |
|
214 CPPUNIT_ASSERT( s.count(star) == 0 ); |
|
215 s.insert(star); |
|
216 CPPUNIT_ASSERT( s.count(star) == 1 ); |
|
217 s.insert(star); |
|
218 CPPUNIT_ASSERT( s.count(star) == 2 ); |
|
219 hmset::iterator i = s.find(char(40)); |
|
220 CPPUNIT_ASSERT( i == s.end() ); |
|
221 |
|
222 i = s.find(star); |
|
223 CPPUNIT_ASSERT( i != s.end() ) |
|
224 CPPUNIT_ASSERT( *i == '*' ); |
|
225 CPPUNIT_ASSERT( s.erase(star) == 2 ); |
|
226 #endif |
|
227 } |
|
228 void HashTest::hset2() |
|
229 { |
|
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 ); |
|
235 |
|
236 p = s.insert(42); |
|
237 CPPUNIT_ASSERT( !p.second ); |
|
238 #endif |
|
239 } |
|
240 |
|
241 void HashTest::insert_erase() |
|
242 { |
|
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; |
|
246 { |
|
247 hmap values; |
|
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 ); |
|
251 |
|
252 CPPUNIT_ASSERT( values.erase("foo") == 1 ); |
|
253 CPPUNIT_ASSERT( values.erase("bar") == 1 ); |
|
254 CPPUNIT_ASSERT( values.erase("abc") == 1 ); |
|
255 } |
|
256 |
|
257 { |
|
258 hmap values; |
|
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 ); |
|
262 |
|
263 CPPUNIT_ASSERT( values.erase("abc") == 1 ); |
|
264 CPPUNIT_ASSERT( values.erase("bar") == 1 ); |
|
265 CPPUNIT_ASSERT( values.erase("foo") == 1 ); |
|
266 } |
|
267 #endif |
|
268 } |
|
269 |
|
270 /* |
|
271 * Here is the test showing why equality operator on hash containers |
|
272 * has no meaning: |
|
273 |
|
274 struct equality_hash_func { |
|
275 size_t operator () (size_t val) const { |
|
276 return val % 10; |
|
277 } |
|
278 }; |
|
279 |
|
280 void HashTest::equality() |
|
281 { |
|
282 hash_set<size_t, equality_hash_func, equal_to<size_t> > s1, s2; |
|
283 |
|
284 s1.insert(10); |
|
285 s1.insert(20); |
|
286 |
|
287 s2.insert(20); |
|
288 s2.insert(10); |
|
289 |
|
290 //s1 and s2 contains both 10 and 20: |
|
291 CPPUNIT_ASSERT( s1 == s2 ); |
|
292 } |
|
293 */ |
|
294 |
|
295 void HashTest::allocator_with_state() |
|
296 { |
|
297 #if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS) |
|
298 char buf1[2048]; |
|
299 StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1)); |
|
300 |
|
301 char buf2[2048]; |
|
302 StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2)); |
|
303 |
|
304 { |
|
305 typedef hash_set<int, hash<int>, equal_to<int>, StackAllocator<int> > HashSetInt; |
|
306 HashSetInt hint1(10, hash<int>(), equal_to<int>(), stack1); |
|
307 |
|
308 int i; |
|
309 for (i = 0; i < 5; ++i) |
|
310 hint1.insert(i); |
|
311 HashSetInt hint1Cpy(hint1); |
|
312 |
|
313 HashSetInt hint2(10, hash<int>(), equal_to<int>(), stack2); |
|
314 for (; i < 10; ++i) |
|
315 hint2.insert(i); |
|
316 HashSetInt hint2Cpy(hint2); |
|
317 |
|
318 hint1.swap(hint2); |
|
319 |
|
320 CPPUNIT_ASSERT( hint1.get_allocator().swaped() ); |
|
321 CPPUNIT_ASSERT( hint2.get_allocator().swaped() ); |
|
322 |
|
323 CPPUNIT_ASSERT( hint1.get_allocator() == stack2 ); |
|
324 CPPUNIT_ASSERT( hint2.get_allocator() == stack1 ); |
|
325 } |
|
326 CPPUNIT_ASSERT( stack1.ok() ); |
|
327 CPPUNIT_ASSERT( stack2.ok() ); |
|
328 #endif |
|
329 } |
|
330 void HashTest::hash_map_cov1() |
|
331 { |
|
332 __UHEAP_MARK; |
|
333 { |
|
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; |
|
338 |
|
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 ) ); |
|
343 |
|
344 hm1.swap( hm2 ); |
|
345 hm1_Iter = hm1.begin( ); |
|
346 CPPUNIT_ASSERT( hm1_Iter -> second == 300); |
|
347 hm1_Iter = hm1.end( ); |
|
348 |
|
349 hm1_cIter = hm1.end( ); |
|
350 hm1.clear(); |
|
351 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
352 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
353 } |
|
354 { |
|
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; |
|
359 |
|
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 ) ); |
|
364 |
|
365 swap( hm1,hm2 ); |
|
366 hm1_Iter = hm1.begin( ); |
|
367 CPPUNIT_ASSERT( hm1_Iter -> second == 300); |
|
368 hm1_Iter = hm1.end( ); |
|
369 |
|
370 hm1_cIter = hm1.end( ); |
|
371 hm1.clear(); |
|
372 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
373 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
374 } |
|
375 __UHEAP_MARKEND; |
|
376 } |
|
377 void HashTest::hash_map_cov2() |
|
378 { |
|
379 __UHEAP_MARK; |
|
380 { |
|
381 hash_map <int, int> hm1; |
|
382 int i,bcount; |
|
383 typedef pair <int, int> Int_Pair; |
|
384 |
|
385 hm1.insert ( Int_Pair ( 1, 1 ) ); |
|
386 i = hm1.size( ); |
|
387 CPPUNIT_ASSERT( i == 1); |
|
388 |
|
389 i = hm1.max_size(); // for covering the api |
|
390 |
|
391 hm1.insert ( Int_Pair ( 2, 4 ) ); |
|
392 i = hm1.size( ); |
|
393 CPPUNIT_ASSERT( i == 2); |
|
394 hm1.resize(10); |
|
395 bcount = hm1.bucket_count(); |
|
396 CPPUNIT_ASSERT( bcount >= 10); |
|
397 hm1.elems_in_bucket(1); |
|
398 } |
|
399 { |
|
400 typedef hash_multimap<int, int> mmap; |
|
401 mmap m; |
|
402 |
|
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 ) ); |
|
407 |
|
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); |
|
414 } |
|
415 { |
|
416 typedef hash_multimap<int, int> mmap; |
|
417 mmap m; |
|
418 |
|
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 ) ); |
|
423 |
|
424 m.erase(m.begin()); |
|
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 ); |
|
430 } |
|
431 __UHEAP_MARKEND; |
|
432 } |
|
433 void HashTest::hash_map_cov3() |
|
434 { |
|
435 __UHEAP_MARK; |
|
436 { |
|
437 typedef hash_multimap<int, int> mmap; |
|
438 mmap m; |
|
439 |
|
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 ) ); |
|
444 |
|
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); |
|
449 |
|
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); |
|
455 } |
|
456 { |
|
457 typedef hash_multimap<int, int> mmap; |
|
458 typedef allocator<std::pair<int, int> > Myalloc; |
|
459 mmap m; |
|
460 |
|
461 mmap::allocator_type al = m.get_allocator(); |
|
462 CPPUNIT_ASSERT ((al == Myalloc()) == true); |
|
463 |
|
464 mmap::hasher hfn = m.hash_funct(); // returns the hasher function |
|
465 } |
|
466 { |
|
467 typedef hash_multimap<int, int> mmap; |
|
468 mmap m1,m2; |
|
469 |
|
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 ) ); |
|
474 |
|
475 m2.insert ( m1.begin(),m1.end()); |
|
476 mmap::iterator i1 = m2.begin(); |
|
477 CPPUNIT_ASSERT( i1 -> second == 10); |
|
478 } |
|
479 __UHEAP_MARKEND; |
|
480 } |
|
481 void HashTest::hash_map_cov4() |
|
482 { |
|
483 __UHEAP_MARK; |
|
484 { |
|
485 typedef hash_map<int, int> mmap; |
|
486 mmap m; |
|
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 ) ); |
|
491 |
|
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); |
|
498 } |
|
499 { |
|
500 typedef hash_map<int, int> mmap; |
|
501 mmap m; |
|
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 ) ); |
|
506 |
|
507 m.erase(m.begin()); |
|
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 ); |
|
513 } |
|
514 { |
|
515 typedef hash_map<int, int> mmap; |
|
516 mmap m; |
|
517 |
|
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 ) ); |
|
522 |
|
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); |
|
527 } |
|
528 __UHEAP_MARKEND; |
|
529 } |
|
530 void HashTest::hash_map_cov5() |
|
531 { |
|
532 __UHEAP_MARK; |
|
533 { |
|
534 typedef hash_map<int, int> mmap; |
|
535 typedef allocator<std::pair<int, int> > Myalloc; |
|
536 mmap m; |
|
537 mmap::allocator_type al = m.get_allocator(); |
|
538 CPPUNIT_ASSERT ((al == Myalloc()) == true); |
|
539 |
|
540 mmap::hasher hfn = m.hash_funct(); // returns the hasher function |
|
541 } |
|
542 { |
|
543 typedef hash_map<int, int> mmap; |
|
544 mmap m1,m2; |
|
545 |
|
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 ) ); |
|
550 |
|
551 m2.insert ( m1.begin(),m1.end()); |
|
552 mmap::iterator i1 = m2.begin(); |
|
553 CPPUNIT_ASSERT( i1 -> second == 10); |
|
554 } |
|
555 { |
|
556 typedef hash_map<char, int> mmap; |
|
557 mmap c1; |
|
558 mmap::key_equal cmpfn = c1.key_eq(); |
|
559 CPPUNIT_ASSERT( cmpfn('a','a') == true); |
|
560 |
|
561 c1.max_bucket_count(); // for covering the api |
|
562 } |
|
563 { |
|
564 typedef hash_map<int, int> mmap; |
|
565 mmap m1; |
|
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 ) ); |
|
570 |
|
571 mmap::iterator i1 = m1.begin(); |
|
572 CPPUNIT_ASSERT( i1 -> second == 10); |
|
573 } |
|
574 __UHEAP_MARKEND; |
|
575 } |
|
576 void HashTest::hash_map_cov6() |
|
577 { |
|
578 __UHEAP_MARK; |
|
579 { |
|
580 typedef hash_map<int, int> mmap; |
|
581 mmap m1; |
|
582 int bcount; |
|
583 |
|
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 ) ); |
|
588 |
|
589 mmap m2(m1); |
|
590 mmap::iterator i1 = m2.begin(); |
|
591 CPPUNIT_ASSERT( i1 -> second == 10); |
|
592 |
|
593 mmap m3(10); |
|
594 bcount = m3.bucket_count(); |
|
595 CPPUNIT_ASSERT( bcount >= 10); |
|
596 |
|
597 mmap::hasher hfn = m1.hash_funct(); |
|
598 mmap m4(20,hfn); |
|
599 bcount = m4.bucket_count(); |
|
600 CPPUNIT_ASSERT( bcount >= 20); |
|
601 |
|
602 mmap m5(m1.begin(),m2.end()); |
|
603 CPPUNIT_ASSERT( m5.size() == 3); |
|
604 |
|
605 mmap m6(m1.begin(),m2.end(),30); |
|
606 CPPUNIT_ASSERT( m6.size() == 3); |
|
607 bcount = m6.bucket_count(); |
|
608 CPPUNIT_ASSERT( bcount >= 30); |
|
609 |
|
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); |
|
614 |
|
615 mmap::key_equal cmpfn;// = c1.key_eq(); |
|
616 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn); |
|
617 |
|
618 mmap m9(30,hfn,cmpfn); |
|
619 } |
|
620 __UHEAP_MARKEND; |
|
621 } |
|
622 |
|
623 void HashTest::hash_multimap_cov1() |
|
624 { |
|
625 __UHEAP_MARK; |
|
626 { |
|
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; |
|
631 |
|
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 ) ); |
|
636 |
|
637 hm1.swap( hm2 ); |
|
638 hm1_Iter = hm1.begin( ); |
|
639 CPPUNIT_ASSERT( hm1_Iter -> second == 300); |
|
640 hm1_Iter = hm1.end( ); |
|
641 hm1_cIter = hm1.end( ); |
|
642 hm1.clear(); |
|
643 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
644 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
645 } |
|
646 { |
|
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; |
|
651 |
|
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 ) ); |
|
656 |
|
657 swap( hm1,hm2 ); |
|
658 hm1_Iter = hm1.begin( ); |
|
659 CPPUNIT_ASSERT( hm1_Iter -> second == 300); |
|
660 hm1_Iter = hm1.end( ); |
|
661 hm1_cIter = hm1.end( ); |
|
662 hm1.clear(); |
|
663 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
664 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
665 } |
|
666 __UHEAP_MARKEND; |
|
667 } |
|
668 void HashTest::hash_multimap_cov2() |
|
669 { |
|
670 __UHEAP_MARK; |
|
671 { |
|
672 hash_multimap <int, int> hm1; |
|
673 int i,bcount; |
|
674 typedef pair <int, int> Int_Pair; |
|
675 |
|
676 hm1.insert ( Int_Pair ( 1, 1 ) ); |
|
677 i = hm1.size( ); |
|
678 CPPUNIT_ASSERT( i == 1); |
|
679 |
|
680 i = hm1.max_size(); // for covering the api |
|
681 |
|
682 hm1.insert ( Int_Pair ( 2, 4 ) ); |
|
683 i = hm1.size( ); |
|
684 CPPUNIT_ASSERT( i == 2); |
|
685 hm1.resize(10); |
|
686 bcount = hm1.bucket_count(); |
|
687 CPPUNIT_ASSERT( bcount >= 10); |
|
688 hm1.elems_in_bucket(1); |
|
689 } |
|
690 { |
|
691 typedef hash_multimap<int, int> mmap; |
|
692 mmap m1; |
|
693 |
|
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 ) ); |
|
698 |
|
699 mmap::iterator i1 = m1.begin(); |
|
700 CPPUNIT_ASSERT( i1 -> second == 10); |
|
701 } |
|
702 { |
|
703 typedef hash_multimap<char, int> mmap; |
|
704 mmap c1; |
|
705 mmap::key_equal cmpfn = c1.key_eq(); |
|
706 CPPUNIT_ASSERT( cmpfn('a','a') == true); |
|
707 |
|
708 c1.max_bucket_count(); // for covering the api |
|
709 } |
|
710 __UHEAP_MARKEND; |
|
711 } |
|
712 void HashTest::hash_multimap_cov3() |
|
713 { |
|
714 __UHEAP_MARK; |
|
715 { |
|
716 typedef hash_multimap<int, int> mmap; |
|
717 mmap m1; |
|
718 int bcount; |
|
719 |
|
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 ) ); |
|
724 |
|
725 mmap m2(m1); |
|
726 mmap::iterator i1 = m2.begin(); |
|
727 CPPUNIT_ASSERT( i1 -> second == 10); |
|
728 |
|
729 mmap m3(10); |
|
730 bcount = m3.bucket_count(); |
|
731 CPPUNIT_ASSERT( bcount >= 10); |
|
732 |
|
733 mmap::hasher hfn = m1.hash_funct(); |
|
734 mmap m4(20,hfn); |
|
735 bcount = m4.bucket_count(); |
|
736 CPPUNIT_ASSERT( bcount >= 20); |
|
737 |
|
738 mmap m5(m1.begin(),m2.end()); |
|
739 CPPUNIT_ASSERT( m5.size() == 3); |
|
740 |
|
741 mmap m6(m1.begin(),m2.end(),30); |
|
742 CPPUNIT_ASSERT( m6.size() == 3); |
|
743 bcount = m6.bucket_count(); |
|
744 CPPUNIT_ASSERT( bcount >= 30); |
|
745 |
|
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); |
|
750 |
|
751 mmap::key_equal cmpfn; |
|
752 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn); |
|
753 |
|
754 mmap m9(30,hfn,cmpfn); |
|
755 } |
|
756 __UHEAP_MARKEND; |
|
757 } |
|
758 |
|
759 void HashTest::hash_set_cov1() |
|
760 { |
|
761 __UHEAP_MARK; |
|
762 { |
|
763 hash_set <int> hm1, hm2; |
|
764 hash_set <int>::iterator hm1_Iter; |
|
765 hash_set <int>::const_iterator hm1_cIter; |
|
766 |
|
767 hm1.insert ( 10 ); |
|
768 hm1.insert ( 20 ); |
|
769 hm1.insert ( 30 ); |
|
770 hm2.insert ( 300 ); |
|
771 |
|
772 hm1.swap( hm2 ); |
|
773 hm1_Iter = hm1.begin( ); |
|
774 CPPUNIT_ASSERT( *hm1_Iter == 300); |
|
775 hm1_Iter = hm1.end( ); |
|
776 hm1_cIter = hm1.end( ); |
|
777 hm1.clear(); |
|
778 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
779 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
780 } |
|
781 { |
|
782 hash_set <int> hm1, hm2; |
|
783 hash_set <int>::iterator hm1_Iter; |
|
784 hash_set <int>::const_iterator hm1_cIter; |
|
785 |
|
786 hm1.insert ( 10 ); |
|
787 hm1.insert ( 20 ); |
|
788 hm1.insert ( 30 ); |
|
789 hm2.insert ( 300 ); |
|
790 |
|
791 swap( hm1,hm2 ); |
|
792 hm1_Iter = hm1.begin( ); |
|
793 CPPUNIT_ASSERT( *hm1_Iter == 300); |
|
794 hm1_Iter = hm1.end( ); |
|
795 hm1_cIter = hm1.end( ); |
|
796 hm1.clear(); |
|
797 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
798 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
799 } |
|
800 __UHEAP_MARKEND; |
|
801 } |
|
802 void HashTest::hash_set_cov2() |
|
803 { |
|
804 __UHEAP_MARK; |
|
805 { |
|
806 hash_set <int> hm1; |
|
807 int i,bcount; |
|
808 |
|
809 hm1.insert ( 1 ); |
|
810 i = hm1.size( ); |
|
811 CPPUNIT_ASSERT( i == 1); |
|
812 |
|
813 i = hm1.max_size(); // for covering the api |
|
814 |
|
815 hm1.insert ( 4 ); |
|
816 i = hm1.size( ); |
|
817 CPPUNIT_ASSERT( i == 2); |
|
818 hm1.resize(10); |
|
819 bcount = hm1.bucket_count(); |
|
820 CPPUNIT_ASSERT( bcount >= 10); |
|
821 hm1.elems_in_bucket(1); |
|
822 } |
|
823 { |
|
824 typedef hash_multiset<int> mmap; |
|
825 mmap m; |
|
826 |
|
827 m.insert ( 10 ); |
|
828 m.insert ( 20 ); |
|
829 m.insert ( 30 ); |
|
830 |
|
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()); |
|
838 } |
|
839 { |
|
840 typedef hash_multiset<int> mmap; |
|
841 mmap m; |
|
842 |
|
843 m.insert ( 10 ); |
|
844 m.insert ( 20 ); |
|
845 m.insert ( 30 ); |
|
846 |
|
847 m.erase(m.begin()); |
|
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 ); |
|
853 } |
|
854 __UHEAP_MARKEND; |
|
855 } |
|
856 void HashTest::hash_set_cov3() |
|
857 { |
|
858 __UHEAP_MARK; |
|
859 { |
|
860 typedef hash_multiset<int> mmap; |
|
861 mmap m; |
|
862 |
|
863 m.insert ( 10 ); |
|
864 m.insert ( 20 ); |
|
865 m.insert ( 30 ); |
|
866 |
|
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); |
|
871 } |
|
872 { |
|
873 typedef hash_multiset<int> mmap; |
|
874 typedef allocator<std::pair<int, int> > Myalloc; |
|
875 mmap m; |
|
876 |
|
877 mmap::allocator_type al = m.get_allocator(); |
|
878 CPPUNIT_ASSERT ((al == Myalloc()) == true); |
|
879 |
|
880 mmap::hasher hfn = m.hash_funct(); // returns the hasher function |
|
881 } |
|
882 { |
|
883 typedef hash_multiset<int> mmap; |
|
884 mmap m1,m2; |
|
885 |
|
886 m1.insert ( 10 ); |
|
887 m1.insert ( 20 ); |
|
888 m1.insert ( 30 ); |
|
889 |
|
890 m2.insert ( m1.begin(),m1.end()); |
|
891 mmap::iterator i1 = m2.begin(); |
|
892 CPPUNIT_ASSERT( *i1 == 10); |
|
893 } |
|
894 |
|
895 { |
|
896 typedef hash_set<int> mmap; |
|
897 mmap m; |
|
898 |
|
899 m.insert ( 10 ); |
|
900 m.insert ( 20 ); |
|
901 m.insert ( 30 ); |
|
902 |
|
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()); } |
|
910 __UHEAP_MARKEND; |
|
911 } |
|
912 void HashTest::hash_set_cov4() |
|
913 { |
|
914 __UHEAP_MARK; |
|
915 { |
|
916 typedef hash_set<int> mmap; |
|
917 mmap m; |
|
918 |
|
919 m.insert ( 10 ); |
|
920 m.insert ( 20 ); |
|
921 m.insert ( 30 ); |
|
922 |
|
923 m.erase(m.begin()); |
|
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 ); |
|
929 } |
|
930 { |
|
931 typedef hash_set<int> mmap; |
|
932 mmap m; |
|
933 |
|
934 m.insert ( 10 ); |
|
935 m.insert ( 20 ); |
|
936 m.insert ( 30 ); |
|
937 |
|
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); |
|
942 } |
|
943 { |
|
944 typedef hash_set<int> mmap; |
|
945 typedef allocator<std::pair<int, int> > Myalloc; |
|
946 mmap m; |
|
947 |
|
948 mmap::allocator_type al = m.get_allocator(); |
|
949 CPPUNIT_ASSERT ((al == Myalloc()) == true); |
|
950 |
|
951 mmap::hasher hfn = m.hash_funct(); // returns the hasher function |
|
952 } |
|
953 __UHEAP_MARKEND; |
|
954 } |
|
955 void HashTest::hash_set_cov5() |
|
956 { |
|
957 __UHEAP_MARK; |
|
958 { |
|
959 typedef hash_set<int> mmap; |
|
960 mmap m1,m2; |
|
961 |
|
962 m1.insert ( 10 ); |
|
963 m1.insert ( 20 ); |
|
964 m1.insert ( 30 ); |
|
965 |
|
966 m2.insert ( m1.begin(),m1.end()); |
|
967 mmap::iterator i1 = m2.begin(); |
|
968 CPPUNIT_ASSERT( *i1 == 10); |
|
969 } |
|
970 { |
|
971 typedef hash_set<char> mmap; |
|
972 mmap c1; |
|
973 mmap::key_equal cmpfn = c1.key_eq(); |
|
974 CPPUNIT_ASSERT( cmpfn('a','a') == true); |
|
975 |
|
976 c1.max_bucket_count(); // for covering the api |
|
977 } |
|
978 { |
|
979 typedef hash_set<int> mmap; |
|
980 mmap m1; |
|
981 |
|
982 m1.insert_noresize ( 10 ); |
|
983 m1.insert_noresize ( 20 ); |
|
984 m1.insert_noresize ( 30 ); |
|
985 |
|
986 mmap::iterator i1 = m1.begin(); |
|
987 CPPUNIT_ASSERT( *i1 == 10); |
|
988 } |
|
989 { |
|
990 typedef hash_set<int> mmap; |
|
991 mmap m1; |
|
992 int bcount; |
|
993 |
|
994 m1.insert ( 10 ); |
|
995 m1.insert ( 20 ); |
|
996 m1.insert ( 30 ); |
|
997 |
|
998 mmap m2(m1); |
|
999 mmap::iterator i1 = m2.begin(); |
|
1000 CPPUNIT_ASSERT( *i1 == 10); |
|
1001 |
|
1002 mmap m3(10); |
|
1003 bcount = m3.bucket_count(); |
|
1004 CPPUNIT_ASSERT( bcount >= 10); |
|
1005 |
|
1006 mmap::hasher hfn = m1.hash_funct(); |
|
1007 mmap m4(20,hfn); |
|
1008 bcount = m4.bucket_count(); |
|
1009 CPPUNIT_ASSERT( bcount >= 20); |
|
1010 |
|
1011 mmap m5(m1.begin(),m2.end()); |
|
1012 CPPUNIT_ASSERT( m5.size() == 3); |
|
1013 |
|
1014 mmap m6(m1.begin(),m2.end(),30); |
|
1015 CPPUNIT_ASSERT( m6.size() == 3); |
|
1016 bcount = m6.bucket_count(); |
|
1017 CPPUNIT_ASSERT( bcount >= 30); |
|
1018 |
|
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); |
|
1023 |
|
1024 mmap::key_equal cmpfn;// = c1.key_eq(); |
|
1025 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn); |
|
1026 |
|
1027 mmap m9(30,hfn,cmpfn); |
|
1028 } |
|
1029 __UHEAP_MARKEND; |
|
1030 } |
|
1031 void HashTest::hash_set_cov6() |
|
1032 { |
|
1033 __UHEAP_MARK; |
|
1034 { |
|
1035 typedef hash_set<int> mmap; |
|
1036 mmap m1; |
|
1037 |
|
1038 m1.insert ( 10 ); |
|
1039 m1.insert ( 20 ); |
|
1040 m1.insert ( 30 ); |
|
1041 |
|
1042 CPPUNIT_ASSERT( m1.count(10) == 1); |
|
1043 CPPUNIT_ASSERT( m1.erase(10) == 1); |
|
1044 CPPUNIT_ASSERT( m1.count(10) == 0); |
|
1045 } |
|
1046 { |
|
1047 hash_set <int> hm1; |
|
1048 hash_set <int>::iterator hm1_Iter; |
|
1049 hm1.insert ( 10 ); |
|
1050 hm1.insert ( 20 ); |
|
1051 hm1.insert ( 30 ); |
|
1052 hm1_Iter = hm1.begin( ); |
|
1053 CPPUNIT_ASSERT( *hm1_Iter == 10); |
|
1054 hm1_Iter ++ ; |
|
1055 CPPUNIT_ASSERT( *hm1_Iter == 20); |
|
1056 hm1_Iter ++ ; |
|
1057 CPPUNIT_ASSERT( *hm1_Iter == 30); |
|
1058 |
|
1059 } |
|
1060 __UHEAP_MARKEND; |
|
1061 } |
|
1062 |
|
1063 void HashTest::hash_multiset_cov1() |
|
1064 { |
|
1065 __UHEAP_MARK; |
|
1066 { |
|
1067 hash_multiset <int> hm1, hm2; |
|
1068 hash_multiset <int>::iterator hm1_Iter; |
|
1069 hash_multiset <int>::const_iterator hm1_cIter; |
|
1070 |
|
1071 hm1.insert ( 10 ); |
|
1072 hm1.insert ( 20 ); |
|
1073 hm1.insert ( 30 ); |
|
1074 hm2.insert ( 300 ); |
|
1075 |
|
1076 hm1.swap( hm2 ); |
|
1077 hm1_Iter = hm1.begin( ); |
|
1078 CPPUNIT_ASSERT( *hm1_Iter== 300); |
|
1079 hm1_Iter = hm1.end( ); |
|
1080 hm1_cIter = hm1.end( ); |
|
1081 hm1.clear(); |
|
1082 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
1083 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
1084 } |
|
1085 { |
|
1086 hash_multiset <int> hm1, hm2; |
|
1087 hash_multiset <int>::iterator hm1_Iter; |
|
1088 hash_multiset <int>::const_iterator hm1_cIter; |
|
1089 |
|
1090 hm1.insert ( 10 ); |
|
1091 hm1.insert ( 20 ); |
|
1092 hm1.insert ( 30 ); |
|
1093 hm2.insert ( 300 ); |
|
1094 |
|
1095 swap( hm1,hm2 ); |
|
1096 hm1_Iter = hm1.begin( ); |
|
1097 CPPUNIT_ASSERT( *hm1_Iter== 300); |
|
1098 hm1_Iter = hm1.end( ); |
|
1099 hm1_cIter = hm1.end( ); |
|
1100 hm1.clear(); |
|
1101 CPPUNIT_ASSERT( hm1.size() == 0 ); |
|
1102 CPPUNIT_ASSERT( hm1.empty() == true ); |
|
1103 } |
|
1104 __UHEAP_MARKEND; |
|
1105 } |
|
1106 void HashTest::hash_multiset_cov2() |
|
1107 { |
|
1108 __UHEAP_MARK; |
|
1109 { |
|
1110 hash_multiset <int> hm1; |
|
1111 int i,bcount; |
|
1112 |
|
1113 hm1.insert ( 1 ); |
|
1114 i = hm1.size( ); |
|
1115 CPPUNIT_ASSERT( i == 1); |
|
1116 |
|
1117 i = hm1.max_size(); // for covering the api |
|
1118 |
|
1119 hm1.insert ( 4 ); |
|
1120 i = hm1.size( ); |
|
1121 CPPUNIT_ASSERT( i == 2); |
|
1122 hm1.resize(10); |
|
1123 bcount = hm1.bucket_count(); |
|
1124 CPPUNIT_ASSERT( bcount >= 10); |
|
1125 hm1.elems_in_bucket(1); |
|
1126 } |
|
1127 { |
|
1128 typedef hash_multiset<int> mmap; |
|
1129 mmap m1; |
|
1130 |
|
1131 m1.insert_noresize ( 10 ); |
|
1132 m1.insert_noresize ( 20 ); |
|
1133 m1.insert_noresize ( 30 ); |
|
1134 |
|
1135 mmap::iterator i1 = m1.begin(); |
|
1136 CPPUNIT_ASSERT( *i1 == 10); |
|
1137 } |
|
1138 { |
|
1139 typedef hash_multiset<char> mmap; |
|
1140 mmap c1; |
|
1141 mmap::key_equal cmpfn = c1.key_eq(); |
|
1142 CPPUNIT_ASSERT( cmpfn('a','a') == true); |
|
1143 |
|
1144 c1.max_bucket_count(); // for covering the api |
|
1145 } |
|
1146 __UHEAP_MARKEND; |
|
1147 } |
|
1148 void HashTest::hash_multiset_cov3() |
|
1149 { |
|
1150 __UHEAP_MARK; |
|
1151 { |
|
1152 typedef hash_multiset<int> mmap; |
|
1153 mmap m1; |
|
1154 int bcount; |
|
1155 |
|
1156 m1.insert ( 10 ); |
|
1157 m1.insert ( 20 ); |
|
1158 m1.insert ( 30 ); |
|
1159 |
|
1160 mmap m2(m1); |
|
1161 mmap::iterator i1 = m2.begin(); |
|
1162 CPPUNIT_ASSERT( *i1 == 10); |
|
1163 |
|
1164 mmap m3(10); |
|
1165 bcount = m3.bucket_count(); |
|
1166 CPPUNIT_ASSERT( bcount >= 10); |
|
1167 |
|
1168 mmap::hasher hfn = m1.hash_funct(); |
|
1169 mmap m4(20,hfn); |
|
1170 bcount = m4.bucket_count(); |
|
1171 CPPUNIT_ASSERT( bcount >= 20); |
|
1172 |
|
1173 mmap m5(m1.begin(),m2.end()); |
|
1174 CPPUNIT_ASSERT( m5.size() == 3); |
|
1175 |
|
1176 mmap m6(m1.begin(),m2.end(),30); |
|
1177 CPPUNIT_ASSERT( m6.size() == 3); |
|
1178 bcount = m6.bucket_count(); |
|
1179 CPPUNIT_ASSERT( bcount >= 30); |
|
1180 |
|
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); |
|
1185 |
|
1186 mmap::key_equal cmpfn;// = c1.key_eq(); |
|
1187 mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn); |
|
1188 |
|
1189 mmap m9(30,hfn,cmpfn); |
|
1190 } |
|
1191 __UHEAP_MARKEND; |
|
1192 } |