sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
//Has to be first for StackAllocator swap overload to be taken
|
sl@0
|
17 |
//into account (at least using GCC 4.0.1)
|
sl@0
|
18 |
#include "stack_allocator.h"
|
sl@0
|
19 |
|
sl@0
|
20 |
#include <vector>
|
sl@0
|
21 |
#include <algorithm>
|
sl@0
|
22 |
#include <e32std.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
25 |
# include <hash_map>
|
sl@0
|
26 |
# include <hash_set>
|
sl@0
|
27 |
# include <rope>
|
sl@0
|
28 |
# endif
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <string>
|
sl@0
|
31 |
|
sl@0
|
32 |
#include "cppunit/cppunit_proxy.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
#if defined (__MVS__)
|
sl@0
|
35 |
const char star = 92;
|
sl@0
|
36 |
#else
|
sl@0
|
37 |
const char star = 42;
|
sl@0
|
38 |
#endif
|
sl@0
|
39 |
|
sl@0
|
40 |
#if !defined (STLPORT) || defined (_STLP_USE_NAMESPACES)
|
sl@0
|
41 |
using namespace std;
|
sl@0
|
42 |
#endif
|
sl@0
|
43 |
|
sl@0
|
44 |
//
|
sl@0
|
45 |
// TestCase class
|
sl@0
|
46 |
//
|
sl@0
|
47 |
class HashTest : public CPPUNIT_NS::TestCase
|
sl@0
|
48 |
{
|
sl@0
|
49 |
CPPUNIT_TEST_SUITE(HashTest);
|
sl@0
|
50 |
#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
51 |
CPPUNIT_IGNORE;
|
sl@0
|
52 |
#endif
|
sl@0
|
53 |
CPPUNIT_TEST(hmap1);
|
sl@0
|
54 |
CPPUNIT_TEST(hmmap1);
|
sl@0
|
55 |
CPPUNIT_TEST(hmset1);
|
sl@0
|
56 |
CPPUNIT_TEST(hset2);
|
sl@0
|
57 |
CPPUNIT_TEST(insert_erase);
|
sl@0
|
58 |
CPPUNIT_TEST(allocator_with_state);
|
sl@0
|
59 |
CPPUNIT_TEST(hash_map_cov1);
|
sl@0
|
60 |
CPPUNIT_TEST(hash_map_cov2);
|
sl@0
|
61 |
CPPUNIT_TEST(hash_map_cov3);
|
sl@0
|
62 |
CPPUNIT_TEST(hash_map_cov4);
|
sl@0
|
63 |
CPPUNIT_TEST(hash_map_cov5);
|
sl@0
|
64 |
CPPUNIT_TEST(hash_map_cov6);
|
sl@0
|
65 |
CPPUNIT_TEST(hash_multimap_cov1);
|
sl@0
|
66 |
CPPUNIT_TEST(hash_multimap_cov2);
|
sl@0
|
67 |
CPPUNIT_TEST(hash_multimap_cov3);
|
sl@0
|
68 |
CPPUNIT_TEST(hash_set_cov1);
|
sl@0
|
69 |
CPPUNIT_TEST(hash_set_cov2);
|
sl@0
|
70 |
CPPUNIT_TEST(hash_set_cov3);
|
sl@0
|
71 |
CPPUNIT_TEST(hash_set_cov4);
|
sl@0
|
72 |
CPPUNIT_TEST(hash_set_cov5);
|
sl@0
|
73 |
CPPUNIT_TEST(hash_set_cov6);
|
sl@0
|
74 |
CPPUNIT_TEST(hash_multiset_cov1);
|
sl@0
|
75 |
CPPUNIT_TEST(hash_multiset_cov2);
|
sl@0
|
76 |
CPPUNIT_TEST(hash_multiset_cov3);
|
sl@0
|
77 |
//CPPUNIT_TEST(equality);
|
sl@0
|
78 |
CPPUNIT_TEST_SUITE_END();
|
sl@0
|
79 |
|
sl@0
|
80 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
81 |
typedef hash_multiset<char, hash<char>, equal_to<char> > hmset;
|
sl@0
|
82 |
#endif
|
sl@0
|
83 |
|
sl@0
|
84 |
protected:
|
sl@0
|
85 |
void hmap1();
|
sl@0
|
86 |
void hmmap1();
|
sl@0
|
87 |
void hmset1();
|
sl@0
|
88 |
void hset2();
|
sl@0
|
89 |
void insert_erase();
|
sl@0
|
90 |
void hash_map_cov1();
|
sl@0
|
91 |
void hash_map_cov2();
|
sl@0
|
92 |
void hash_map_cov3();
|
sl@0
|
93 |
void hash_map_cov4();
|
sl@0
|
94 |
void hash_map_cov5();
|
sl@0
|
95 |
void hash_map_cov6();
|
sl@0
|
96 |
void hash_multimap_cov1();
|
sl@0
|
97 |
void hash_multimap_cov2();
|
sl@0
|
98 |
void hash_multimap_cov3();
|
sl@0
|
99 |
void hash_set_cov1();
|
sl@0
|
100 |
void hash_set_cov2();
|
sl@0
|
101 |
void hash_set_cov3();
|
sl@0
|
102 |
void hash_set_cov4();
|
sl@0
|
103 |
void hash_set_cov5();
|
sl@0
|
104 |
void hash_set_cov6();
|
sl@0
|
105 |
void hash_multiset_cov1();
|
sl@0
|
106 |
void hash_multiset_cov2();
|
sl@0
|
107 |
void hash_multiset_cov3();
|
sl@0
|
108 |
//void equality();
|
sl@0
|
109 |
void allocator_with_state();
|
sl@0
|
110 |
};
|
sl@0
|
111 |
|
sl@0
|
112 |
CPPUNIT_TEST_SUITE_REGISTRATION(HashTest);
|
sl@0
|
113 |
|
sl@0
|
114 |
//
|
sl@0
|
115 |
// tests implementation
|
sl@0
|
116 |
//
|
sl@0
|
117 |
void HashTest::hmap1()
|
sl@0
|
118 |
{
|
sl@0
|
119 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
120 |
typedef hash_map<char, crope, hash<char>, equal_to<char> > maptype;
|
sl@0
|
121 |
maptype m;
|
sl@0
|
122 |
// Store mappings between roman numerals and decimals.
|
sl@0
|
123 |
m['l'] = "50";
|
sl@0
|
124 |
m['x'] = "20"; // Deliberate mistake.
|
sl@0
|
125 |
m['v'] = "5";
|
sl@0
|
126 |
m['i'] = "1";
|
sl@0
|
127 |
CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"20") );
|
sl@0
|
128 |
m['x'] = "10"; // Correct mistake.
|
sl@0
|
129 |
CPPUNIT_ASSERT( !strcmp(m['x'].c_str(),"10") );
|
sl@0
|
130 |
|
sl@0
|
131 |
CPPUNIT_ASSERT( !strcmp(m['z'].c_str(),"") );
|
sl@0
|
132 |
|
sl@0
|
133 |
CPPUNIT_ASSERT( m.count('z')==1 );
|
sl@0
|
134 |
pair<maptype::iterator, bool> p = m.insert(pair<const char, crope>('c', crope("100")));
|
sl@0
|
135 |
|
sl@0
|
136 |
CPPUNIT_ASSERT(p.second);
|
sl@0
|
137 |
|
sl@0
|
138 |
p = m.insert(pair<const char, crope>('c', crope("100")));
|
sl@0
|
139 |
CPPUNIT_ASSERT(!p.second);
|
sl@0
|
140 |
|
sl@0
|
141 |
//Some iterators compare check, really compile time checks
|
sl@0
|
142 |
maptype::iterator ite(m.begin());
|
sl@0
|
143 |
maptype::const_iterator cite(m.begin());
|
sl@0
|
144 |
cite = m.begin();
|
sl@0
|
145 |
maptype const& cm = m;
|
sl@0
|
146 |
cite = cm.begin();
|
sl@0
|
147 |
CPPUNIT_ASSERT( ite == cite );
|
sl@0
|
148 |
CPPUNIT_ASSERT( !(ite != cite) );
|
sl@0
|
149 |
CPPUNIT_ASSERT( cite == ite );
|
sl@0
|
150 |
CPPUNIT_ASSERT( !(cite != ite) );
|
sl@0
|
151 |
#endif
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
void HashTest::hmmap1()
|
sl@0
|
155 |
{
|
sl@0
|
156 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
157 |
typedef hash_multimap<char, int, hash<char>,equal_to<char> > mmap;
|
sl@0
|
158 |
mmap m;
|
sl@0
|
159 |
CPPUNIT_ASSERT(m.count('X')==0);
|
sl@0
|
160 |
m.insert(pair<const char,int>('X', 10)); // Standard way.
|
sl@0
|
161 |
CPPUNIT_ASSERT(m.count('X')==1);
|
sl@0
|
162 |
// m.insert('X', 20); // Non-standard, but very convenient!
|
sl@0
|
163 |
m.insert(pair<const char,int>('X', 20)); // jbuck: standard way
|
sl@0
|
164 |
CPPUNIT_ASSERT(m.count('X')==2);
|
sl@0
|
165 |
// m.insert('Y', 32);
|
sl@0
|
166 |
m.insert(pair<const char,int>('Y', 32)); // jbuck: standard way
|
sl@0
|
167 |
mmap::iterator i = m.find('X'); // Find first match.
|
sl@0
|
168 |
|
sl@0
|
169 |
CPPUNIT_ASSERT((*i).first=='X');
|
sl@0
|
170 |
CPPUNIT_ASSERT((*i).second==10);
|
sl@0
|
171 |
i++;
|
sl@0
|
172 |
CPPUNIT_ASSERT((*i).first=='X');
|
sl@0
|
173 |
CPPUNIT_ASSERT((*i).second==20);
|
sl@0
|
174 |
i++;
|
sl@0
|
175 |
CPPUNIT_ASSERT((*i).first=='Y');
|
sl@0
|
176 |
CPPUNIT_ASSERT((*i).second==32);
|
sl@0
|
177 |
i++;
|
sl@0
|
178 |
CPPUNIT_ASSERT(i==m.end());
|
sl@0
|
179 |
|
sl@0
|
180 |
size_t count = m.erase('X');
|
sl@0
|
181 |
CPPUNIT_ASSERT(count==2);
|
sl@0
|
182 |
|
sl@0
|
183 |
//Some iterators compare check, really compile time checks
|
sl@0
|
184 |
mmap::iterator ite(m.begin());
|
sl@0
|
185 |
mmap::const_iterator cite(m.begin());
|
sl@0
|
186 |
CPPUNIT_ASSERT( ite == cite );
|
sl@0
|
187 |
CPPUNIT_ASSERT( !(ite != cite) );
|
sl@0
|
188 |
CPPUNIT_ASSERT( cite == ite );
|
sl@0
|
189 |
CPPUNIT_ASSERT( !(cite != ite) );
|
sl@0
|
190 |
|
sl@0
|
191 |
typedef hash_multimap<size_t, size_t> HMapType;
|
sl@0
|
192 |
HMapType hmap;
|
sl@0
|
193 |
|
sl@0
|
194 |
//We fill the map to implicitely start a rehash.
|
sl@0
|
195 |
for (size_t counter = 0; counter < 3077; ++counter)
|
sl@0
|
196 |
hmap.insert(HMapType::value_type(1, counter));
|
sl@0
|
197 |
|
sl@0
|
198 |
hmap.insert(HMapType::value_type(12325, 1));
|
sl@0
|
199 |
hmap.insert(HMapType::value_type(12325, 2));
|
sl@0
|
200 |
|
sl@0
|
201 |
CPPUNIT_ASSERT( hmap.count(12325) == 2 );
|
sl@0
|
202 |
|
sl@0
|
203 |
//At this point 23 goes to the same bucket as 12325, it used to reveal a bug.
|
sl@0
|
204 |
hmap.insert(HMapType::value_type(23, 0));
|
sl@0
|
205 |
|
sl@0
|
206 |
CPPUNIT_ASSERT( hmap.count(12325) == 2 );
|
sl@0
|
207 |
#endif
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
void HashTest::hmset1()
|
sl@0
|
211 |
{
|
sl@0
|
212 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
213 |
hmset s;
|
sl@0
|
214 |
CPPUNIT_ASSERT( s.count(star) == 0 );
|
sl@0
|
215 |
s.insert(star);
|
sl@0
|
216 |
CPPUNIT_ASSERT( s.count(star) == 1 );
|
sl@0
|
217 |
s.insert(star);
|
sl@0
|
218 |
CPPUNIT_ASSERT( s.count(star) == 2 );
|
sl@0
|
219 |
hmset::iterator i = s.find(char(40));
|
sl@0
|
220 |
CPPUNIT_ASSERT( i == s.end() );
|
sl@0
|
221 |
|
sl@0
|
222 |
i = s.find(star);
|
sl@0
|
223 |
CPPUNIT_ASSERT( i != s.end() )
|
sl@0
|
224 |
CPPUNIT_ASSERT( *i == '*' );
|
sl@0
|
225 |
CPPUNIT_ASSERT( s.erase(star) == 2 );
|
sl@0
|
226 |
#endif
|
sl@0
|
227 |
}
|
sl@0
|
228 |
void HashTest::hset2()
|
sl@0
|
229 |
{
|
sl@0
|
230 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
231 |
hash_set<int, hash<int>, equal_to<int> > s;
|
sl@0
|
232 |
pair<hash_set<int, hash<int>, equal_to<int> >::iterator, bool> p = s.insert(42);
|
sl@0
|
233 |
CPPUNIT_ASSERT( p.second );
|
sl@0
|
234 |
CPPUNIT_ASSERT( *(p.first) == 42 );
|
sl@0
|
235 |
|
sl@0
|
236 |
p = s.insert(42);
|
sl@0
|
237 |
CPPUNIT_ASSERT( !p.second );
|
sl@0
|
238 |
#endif
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
void HashTest::insert_erase()
|
sl@0
|
242 |
{
|
sl@0
|
243 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
244 |
typedef hash_map<string, size_t, hash<string>, equal_to<string> > hmap;
|
sl@0
|
245 |
typedef hmap::value_type val_type;
|
sl@0
|
246 |
{
|
sl@0
|
247 |
hmap values;
|
sl@0
|
248 |
CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
|
sl@0
|
249 |
CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
|
sl@0
|
250 |
CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
|
sl@0
|
251 |
|
sl@0
|
252 |
CPPUNIT_ASSERT( values.erase("foo") == 1 );
|
sl@0
|
253 |
CPPUNIT_ASSERT( values.erase("bar") == 1 );
|
sl@0
|
254 |
CPPUNIT_ASSERT( values.erase("abc") == 1 );
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
{
|
sl@0
|
258 |
hmap values;
|
sl@0
|
259 |
CPPUNIT_ASSERT( values.insert(val_type("foo", 0)).second );
|
sl@0
|
260 |
CPPUNIT_ASSERT( values.insert(val_type("bar", 0)).second );
|
sl@0
|
261 |
CPPUNIT_ASSERT( values.insert(val_type("abc", 0)).second );
|
sl@0
|
262 |
|
sl@0
|
263 |
CPPUNIT_ASSERT( values.erase("abc") == 1 );
|
sl@0
|
264 |
CPPUNIT_ASSERT( values.erase("bar") == 1 );
|
sl@0
|
265 |
CPPUNIT_ASSERT( values.erase("foo") == 1 );
|
sl@0
|
266 |
}
|
sl@0
|
267 |
#endif
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
/*
|
sl@0
|
271 |
* Here is the test showing why equality operator on hash containers
|
sl@0
|
272 |
* has no meaning:
|
sl@0
|
273 |
|
sl@0
|
274 |
struct equality_hash_func {
|
sl@0
|
275 |
size_t operator () (size_t val) const {
|
sl@0
|
276 |
return val % 10;
|
sl@0
|
277 |
}
|
sl@0
|
278 |
};
|
sl@0
|
279 |
|
sl@0
|
280 |
void HashTest::equality()
|
sl@0
|
281 |
{
|
sl@0
|
282 |
hash_set<size_t, equality_hash_func, equal_to<size_t> > s1, s2;
|
sl@0
|
283 |
|
sl@0
|
284 |
s1.insert(10);
|
sl@0
|
285 |
s1.insert(20);
|
sl@0
|
286 |
|
sl@0
|
287 |
s2.insert(20);
|
sl@0
|
288 |
s2.insert(10);
|
sl@0
|
289 |
|
sl@0
|
290 |
//s1 and s2 contains both 10 and 20:
|
sl@0
|
291 |
CPPUNIT_ASSERT( s1 == s2 );
|
sl@0
|
292 |
}
|
sl@0
|
293 |
*/
|
sl@0
|
294 |
|
sl@0
|
295 |
void HashTest::allocator_with_state()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
sl@0
|
298 |
char buf1[2048];
|
sl@0
|
299 |
StackAllocator<int> stack1(buf1, buf1 + sizeof(buf1));
|
sl@0
|
300 |
|
sl@0
|
301 |
char buf2[2048];
|
sl@0
|
302 |
StackAllocator<int> stack2(buf2, buf2 + sizeof(buf2));
|
sl@0
|
303 |
|
sl@0
|
304 |
{
|
sl@0
|
305 |
typedef hash_set<int, hash<int>, equal_to<int>, StackAllocator<int> > HashSetInt;
|
sl@0
|
306 |
HashSetInt hint1(10, hash<int>(), equal_to<int>(), stack1);
|
sl@0
|
307 |
|
sl@0
|
308 |
int i;
|
sl@0
|
309 |
for (i = 0; i < 5; ++i)
|
sl@0
|
310 |
hint1.insert(i);
|
sl@0
|
311 |
HashSetInt hint1Cpy(hint1);
|
sl@0
|
312 |
|
sl@0
|
313 |
HashSetInt hint2(10, hash<int>(), equal_to<int>(), stack2);
|
sl@0
|
314 |
for (; i < 10; ++i)
|
sl@0
|
315 |
hint2.insert(i);
|
sl@0
|
316 |
HashSetInt hint2Cpy(hint2);
|
sl@0
|
317 |
|
sl@0
|
318 |
hint1.swap(hint2);
|
sl@0
|
319 |
|
sl@0
|
320 |
CPPUNIT_ASSERT( hint1.get_allocator().swaped() );
|
sl@0
|
321 |
CPPUNIT_ASSERT( hint2.get_allocator().swaped() );
|
sl@0
|
322 |
|
sl@0
|
323 |
CPPUNIT_ASSERT( hint1.get_allocator() == stack2 );
|
sl@0
|
324 |
CPPUNIT_ASSERT( hint2.get_allocator() == stack1 );
|
sl@0
|
325 |
}
|
sl@0
|
326 |
CPPUNIT_ASSERT( stack1.ok() );
|
sl@0
|
327 |
CPPUNIT_ASSERT( stack2.ok() );
|
sl@0
|
328 |
#endif
|
sl@0
|
329 |
}
|
sl@0
|
330 |
void HashTest::hash_map_cov1()
|
sl@0
|
331 |
{
|
sl@0
|
332 |
__UHEAP_MARK;
|
sl@0
|
333 |
{
|
sl@0
|
334 |
hash_map <int, int> hm1, hm2;
|
sl@0
|
335 |
hash_map <int, int>::iterator hm1_Iter;
|
sl@0
|
336 |
hash_map <int, int>::const_iterator hm1_cIter;
|
sl@0
|
337 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
338 |
|
sl@0
|
339 |
hm1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
340 |
hm1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
341 |
hm1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
342 |
hm2.insert ( Int_Pair ( 30, 300 ) );
|
sl@0
|
343 |
|
sl@0
|
344 |
hm1.swap( hm2 );
|
sl@0
|
345 |
hm1_Iter = hm1.begin( );
|
sl@0
|
346 |
CPPUNIT_ASSERT( hm1_Iter -> second == 300);
|
sl@0
|
347 |
hm1_Iter = hm1.end( );
|
sl@0
|
348 |
|
sl@0
|
349 |
hm1_cIter = hm1.end( );
|
sl@0
|
350 |
hm1.clear();
|
sl@0
|
351 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
352 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
353 |
}
|
sl@0
|
354 |
{
|
sl@0
|
355 |
hash_map <int, int> hm1, hm2;
|
sl@0
|
356 |
hash_map <int, int>::iterator hm1_Iter;
|
sl@0
|
357 |
hash_map <int, int>::const_iterator hm1_cIter;
|
sl@0
|
358 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
359 |
|
sl@0
|
360 |
hm1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
361 |
hm1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
362 |
hm1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
363 |
hm2.insert ( Int_Pair ( 30, 300 ) );
|
sl@0
|
364 |
|
sl@0
|
365 |
swap( hm1,hm2 );
|
sl@0
|
366 |
hm1_Iter = hm1.begin( );
|
sl@0
|
367 |
CPPUNIT_ASSERT( hm1_Iter -> second == 300);
|
sl@0
|
368 |
hm1_Iter = hm1.end( );
|
sl@0
|
369 |
|
sl@0
|
370 |
hm1_cIter = hm1.end( );
|
sl@0
|
371 |
hm1.clear();
|
sl@0
|
372 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
373 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
374 |
}
|
sl@0
|
375 |
__UHEAP_MARKEND;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
void HashTest::hash_map_cov2()
|
sl@0
|
378 |
{
|
sl@0
|
379 |
__UHEAP_MARK;
|
sl@0
|
380 |
{
|
sl@0
|
381 |
hash_map <int, int> hm1;
|
sl@0
|
382 |
int i,bcount;
|
sl@0
|
383 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
384 |
|
sl@0
|
385 |
hm1.insert ( Int_Pair ( 1, 1 ) );
|
sl@0
|
386 |
i = hm1.size( );
|
sl@0
|
387 |
CPPUNIT_ASSERT( i == 1);
|
sl@0
|
388 |
|
sl@0
|
389 |
i = hm1.max_size(); // for covering the api
|
sl@0
|
390 |
|
sl@0
|
391 |
hm1.insert ( Int_Pair ( 2, 4 ) );
|
sl@0
|
392 |
i = hm1.size( );
|
sl@0
|
393 |
CPPUNIT_ASSERT( i == 2);
|
sl@0
|
394 |
hm1.resize(10);
|
sl@0
|
395 |
bcount = hm1.bucket_count();
|
sl@0
|
396 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
397 |
hm1.elems_in_bucket(1);
|
sl@0
|
398 |
}
|
sl@0
|
399 |
{
|
sl@0
|
400 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
401 |
mmap m;
|
sl@0
|
402 |
|
sl@0
|
403 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
404 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
405 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
406 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
407 |
|
sl@0
|
408 |
std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
|
sl@0
|
409 |
CPPUNIT_ASSERT( pair1.first->first == 2);
|
sl@0
|
410 |
CPPUNIT_ASSERT( pair1.first->second == 20);
|
sl@0
|
411 |
std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
|
sl@0
|
412 |
CPPUNIT_ASSERT( pair2.first->first == 1);
|
sl@0
|
413 |
CPPUNIT_ASSERT( pair2.first->second == 10);
|
sl@0
|
414 |
}
|
sl@0
|
415 |
{
|
sl@0
|
416 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
417 |
mmap m;
|
sl@0
|
418 |
|
sl@0
|
419 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
420 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
421 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
422 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
423 |
|
sl@0
|
424 |
m.erase(m.begin());
|
sl@0
|
425 |
mmap::iterator i1 = m.begin();
|
sl@0
|
426 |
CPPUNIT_ASSERT( i1 -> second == 20);
|
sl@0
|
427 |
CPPUNIT_ASSERT( m.size() == 2 );
|
sl@0
|
428 |
m.erase(m.begin(),m.end());
|
sl@0
|
429 |
CPPUNIT_ASSERT( m.size() == 0 );
|
sl@0
|
430 |
}
|
sl@0
|
431 |
__UHEAP_MARKEND;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
void HashTest::hash_map_cov3()
|
sl@0
|
434 |
{
|
sl@0
|
435 |
__UHEAP_MARK;
|
sl@0
|
436 |
{
|
sl@0
|
437 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
438 |
mmap m;
|
sl@0
|
439 |
|
sl@0
|
440 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
441 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
442 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
443 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
444 |
|
sl@0
|
445 |
mmap::iterator i1 = m.find(1);
|
sl@0
|
446 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
447 |
mmap::const_iterator i2 = m.find(3);
|
sl@0
|
448 |
CPPUNIT_ASSERT( i2 -> second == 30);
|
sl@0
|
449 |
|
sl@0
|
450 |
// negative test case where the element to find is not present in the
|
sl@0
|
451 |
// hash , so it returns the successive element of the last element.
|
sl@0
|
452 |
mmap::iterator i3 = m.find(4);
|
sl@0
|
453 |
mmap::iterator i4 = m.end();
|
sl@0
|
454 |
CPPUNIT_ASSERT( i3 == i4);
|
sl@0
|
455 |
}
|
sl@0
|
456 |
{
|
sl@0
|
457 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
458 |
typedef allocator<std::pair<int, int> > Myalloc;
|
sl@0
|
459 |
mmap m;
|
sl@0
|
460 |
|
sl@0
|
461 |
mmap::allocator_type al = m.get_allocator();
|
sl@0
|
462 |
CPPUNIT_ASSERT ((al == Myalloc()) == true);
|
sl@0
|
463 |
|
sl@0
|
464 |
mmap::hasher hfn = m.hash_funct(); // returns the hasher function
|
sl@0
|
465 |
}
|
sl@0
|
466 |
{
|
sl@0
|
467 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
468 |
mmap m1,m2;
|
sl@0
|
469 |
|
sl@0
|
470 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
471 |
m1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
472 |
m1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
473 |
m1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
474 |
|
sl@0
|
475 |
m2.insert ( m1.begin(),m1.end());
|
sl@0
|
476 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
477 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
478 |
}
|
sl@0
|
479 |
__UHEAP_MARKEND;
|
sl@0
|
480 |
}
|
sl@0
|
481 |
void HashTest::hash_map_cov4()
|
sl@0
|
482 |
{
|
sl@0
|
483 |
__UHEAP_MARK;
|
sl@0
|
484 |
{
|
sl@0
|
485 |
typedef hash_map<int, int> mmap;
|
sl@0
|
486 |
mmap m;
|
sl@0
|
487 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
488 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
489 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
490 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
491 |
|
sl@0
|
492 |
std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(2);
|
sl@0
|
493 |
CPPUNIT_ASSERT( pair1.first->first == 2);
|
sl@0
|
494 |
CPPUNIT_ASSERT( pair1.first->second == 20);
|
sl@0
|
495 |
std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(1);
|
sl@0
|
496 |
CPPUNIT_ASSERT( pair2.first->first == 1);
|
sl@0
|
497 |
CPPUNIT_ASSERT( pair2.first->second == 10);
|
sl@0
|
498 |
}
|
sl@0
|
499 |
{
|
sl@0
|
500 |
typedef hash_map<int, int> mmap;
|
sl@0
|
501 |
mmap m;
|
sl@0
|
502 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
503 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
504 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
505 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
506 |
|
sl@0
|
507 |
m.erase(m.begin());
|
sl@0
|
508 |
mmap::iterator i1 = m.begin();
|
sl@0
|
509 |
CPPUNIT_ASSERT( i1 -> second == 20);
|
sl@0
|
510 |
CPPUNIT_ASSERT( m.size() == 2 );
|
sl@0
|
511 |
m.erase(m.begin(),m.end());
|
sl@0
|
512 |
CPPUNIT_ASSERT( m.size() == 0 );
|
sl@0
|
513 |
}
|
sl@0
|
514 |
{
|
sl@0
|
515 |
typedef hash_map<int, int> mmap;
|
sl@0
|
516 |
mmap m;
|
sl@0
|
517 |
|
sl@0
|
518 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
519 |
m.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
520 |
m.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
521 |
m.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
522 |
|
sl@0
|
523 |
mmap::iterator i1 = m.find(1);
|
sl@0
|
524 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
525 |
mmap::const_iterator i2 = m.find(3);
|
sl@0
|
526 |
CPPUNIT_ASSERT( i2 -> second == 30);
|
sl@0
|
527 |
}
|
sl@0
|
528 |
__UHEAP_MARKEND;
|
sl@0
|
529 |
}
|
sl@0
|
530 |
void HashTest::hash_map_cov5()
|
sl@0
|
531 |
{
|
sl@0
|
532 |
__UHEAP_MARK;
|
sl@0
|
533 |
{
|
sl@0
|
534 |
typedef hash_map<int, int> mmap;
|
sl@0
|
535 |
typedef allocator<std::pair<int, int> > Myalloc;
|
sl@0
|
536 |
mmap m;
|
sl@0
|
537 |
mmap::allocator_type al = m.get_allocator();
|
sl@0
|
538 |
CPPUNIT_ASSERT ((al == Myalloc()) == true);
|
sl@0
|
539 |
|
sl@0
|
540 |
mmap::hasher hfn = m.hash_funct(); // returns the hasher function
|
sl@0
|
541 |
}
|
sl@0
|
542 |
{
|
sl@0
|
543 |
typedef hash_map<int, int> mmap;
|
sl@0
|
544 |
mmap m1,m2;
|
sl@0
|
545 |
|
sl@0
|
546 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
547 |
m1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
548 |
m1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
549 |
m1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
550 |
|
sl@0
|
551 |
m2.insert ( m1.begin(),m1.end());
|
sl@0
|
552 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
553 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
554 |
}
|
sl@0
|
555 |
{
|
sl@0
|
556 |
typedef hash_map<char, int> mmap;
|
sl@0
|
557 |
mmap c1;
|
sl@0
|
558 |
mmap::key_equal cmpfn = c1.key_eq();
|
sl@0
|
559 |
CPPUNIT_ASSERT( cmpfn('a','a') == true);
|
sl@0
|
560 |
|
sl@0
|
561 |
c1.max_bucket_count(); // for covering the api
|
sl@0
|
562 |
}
|
sl@0
|
563 |
{
|
sl@0
|
564 |
typedef hash_map<int, int> mmap;
|
sl@0
|
565 |
mmap m1;
|
sl@0
|
566 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
567 |
m1.insert_noresize ( Int_Pair ( 1, 10 ) );
|
sl@0
|
568 |
m1.insert_noresize ( Int_Pair ( 2, 20 ) );
|
sl@0
|
569 |
m1.insert_noresize ( Int_Pair ( 3, 30 ) );
|
sl@0
|
570 |
|
sl@0
|
571 |
mmap::iterator i1 = m1.begin();
|
sl@0
|
572 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
573 |
}
|
sl@0
|
574 |
__UHEAP_MARKEND;
|
sl@0
|
575 |
}
|
sl@0
|
576 |
void HashTest::hash_map_cov6()
|
sl@0
|
577 |
{
|
sl@0
|
578 |
__UHEAP_MARK;
|
sl@0
|
579 |
{
|
sl@0
|
580 |
typedef hash_map<int, int> mmap;
|
sl@0
|
581 |
mmap m1;
|
sl@0
|
582 |
int bcount;
|
sl@0
|
583 |
|
sl@0
|
584 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
585 |
m1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
586 |
m1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
587 |
m1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
588 |
|
sl@0
|
589 |
mmap m2(m1);
|
sl@0
|
590 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
591 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
592 |
|
sl@0
|
593 |
mmap m3(10);
|
sl@0
|
594 |
bcount = m3.bucket_count();
|
sl@0
|
595 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
596 |
|
sl@0
|
597 |
mmap::hasher hfn = m1.hash_funct();
|
sl@0
|
598 |
mmap m4(20,hfn);
|
sl@0
|
599 |
bcount = m4.bucket_count();
|
sl@0
|
600 |
CPPUNIT_ASSERT( bcount >= 20);
|
sl@0
|
601 |
|
sl@0
|
602 |
mmap m5(m1.begin(),m2.end());
|
sl@0
|
603 |
CPPUNIT_ASSERT( m5.size() == 3);
|
sl@0
|
604 |
|
sl@0
|
605 |
mmap m6(m1.begin(),m2.end(),30);
|
sl@0
|
606 |
CPPUNIT_ASSERT( m6.size() == 3);
|
sl@0
|
607 |
bcount = m6.bucket_count();
|
sl@0
|
608 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
609 |
|
sl@0
|
610 |
mmap m7(m1.begin(),m2.end(),30,hfn);
|
sl@0
|
611 |
CPPUNIT_ASSERT( m7.size() == 3);
|
sl@0
|
612 |
bcount = m7.bucket_count();
|
sl@0
|
613 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
614 |
|
sl@0
|
615 |
mmap::key_equal cmpfn;// = c1.key_eq();
|
sl@0
|
616 |
mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
|
sl@0
|
617 |
|
sl@0
|
618 |
mmap m9(30,hfn,cmpfn);
|
sl@0
|
619 |
}
|
sl@0
|
620 |
__UHEAP_MARKEND;
|
sl@0
|
621 |
}
|
sl@0
|
622 |
|
sl@0
|
623 |
void HashTest::hash_multimap_cov1()
|
sl@0
|
624 |
{
|
sl@0
|
625 |
__UHEAP_MARK;
|
sl@0
|
626 |
{
|
sl@0
|
627 |
hash_multimap <int, int> hm1, hm2;
|
sl@0
|
628 |
hash_multimap <int, int>::iterator hm1_Iter;
|
sl@0
|
629 |
hash_multimap <int, int>::const_iterator hm1_cIter;
|
sl@0
|
630 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
631 |
|
sl@0
|
632 |
hm1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
633 |
hm1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
634 |
hm1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
635 |
hm2.insert ( Int_Pair ( 30, 300 ) );
|
sl@0
|
636 |
|
sl@0
|
637 |
hm1.swap( hm2 );
|
sl@0
|
638 |
hm1_Iter = hm1.begin( );
|
sl@0
|
639 |
CPPUNIT_ASSERT( hm1_Iter -> second == 300);
|
sl@0
|
640 |
hm1_Iter = hm1.end( );
|
sl@0
|
641 |
hm1_cIter = hm1.end( );
|
sl@0
|
642 |
hm1.clear();
|
sl@0
|
643 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
644 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
645 |
}
|
sl@0
|
646 |
{
|
sl@0
|
647 |
hash_multimap <int, int> hm1, hm2;
|
sl@0
|
648 |
hash_multimap <int, int>::iterator hm1_Iter;
|
sl@0
|
649 |
hash_multimap <int, int>::const_iterator hm1_cIter;
|
sl@0
|
650 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
651 |
|
sl@0
|
652 |
hm1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
653 |
hm1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
654 |
hm1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
655 |
hm2.insert ( Int_Pair ( 30, 300 ) );
|
sl@0
|
656 |
|
sl@0
|
657 |
swap( hm1,hm2 );
|
sl@0
|
658 |
hm1_Iter = hm1.begin( );
|
sl@0
|
659 |
CPPUNIT_ASSERT( hm1_Iter -> second == 300);
|
sl@0
|
660 |
hm1_Iter = hm1.end( );
|
sl@0
|
661 |
hm1_cIter = hm1.end( );
|
sl@0
|
662 |
hm1.clear();
|
sl@0
|
663 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
664 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
665 |
}
|
sl@0
|
666 |
__UHEAP_MARKEND;
|
sl@0
|
667 |
}
|
sl@0
|
668 |
void HashTest::hash_multimap_cov2()
|
sl@0
|
669 |
{
|
sl@0
|
670 |
__UHEAP_MARK;
|
sl@0
|
671 |
{
|
sl@0
|
672 |
hash_multimap <int, int> hm1;
|
sl@0
|
673 |
int i,bcount;
|
sl@0
|
674 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
675 |
|
sl@0
|
676 |
hm1.insert ( Int_Pair ( 1, 1 ) );
|
sl@0
|
677 |
i = hm1.size( );
|
sl@0
|
678 |
CPPUNIT_ASSERT( i == 1);
|
sl@0
|
679 |
|
sl@0
|
680 |
i = hm1.max_size(); // for covering the api
|
sl@0
|
681 |
|
sl@0
|
682 |
hm1.insert ( Int_Pair ( 2, 4 ) );
|
sl@0
|
683 |
i = hm1.size( );
|
sl@0
|
684 |
CPPUNIT_ASSERT( i == 2);
|
sl@0
|
685 |
hm1.resize(10);
|
sl@0
|
686 |
bcount = hm1.bucket_count();
|
sl@0
|
687 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
688 |
hm1.elems_in_bucket(1);
|
sl@0
|
689 |
}
|
sl@0
|
690 |
{
|
sl@0
|
691 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
692 |
mmap m1;
|
sl@0
|
693 |
|
sl@0
|
694 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
695 |
m1.insert_noresize ( Int_Pair ( 1, 10 ) );
|
sl@0
|
696 |
m1.insert_noresize ( Int_Pair ( 2, 20 ) );
|
sl@0
|
697 |
m1.insert_noresize ( Int_Pair ( 3, 30 ) );
|
sl@0
|
698 |
|
sl@0
|
699 |
mmap::iterator i1 = m1.begin();
|
sl@0
|
700 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
701 |
}
|
sl@0
|
702 |
{
|
sl@0
|
703 |
typedef hash_multimap<char, int> mmap;
|
sl@0
|
704 |
mmap c1;
|
sl@0
|
705 |
mmap::key_equal cmpfn = c1.key_eq();
|
sl@0
|
706 |
CPPUNIT_ASSERT( cmpfn('a','a') == true);
|
sl@0
|
707 |
|
sl@0
|
708 |
c1.max_bucket_count(); // for covering the api
|
sl@0
|
709 |
}
|
sl@0
|
710 |
__UHEAP_MARKEND;
|
sl@0
|
711 |
}
|
sl@0
|
712 |
void HashTest::hash_multimap_cov3()
|
sl@0
|
713 |
{
|
sl@0
|
714 |
__UHEAP_MARK;
|
sl@0
|
715 |
{
|
sl@0
|
716 |
typedef hash_multimap<int, int> mmap;
|
sl@0
|
717 |
mmap m1;
|
sl@0
|
718 |
int bcount;
|
sl@0
|
719 |
|
sl@0
|
720 |
typedef pair <int, int> Int_Pair;
|
sl@0
|
721 |
m1.insert ( Int_Pair ( 1, 10 ) );
|
sl@0
|
722 |
m1.insert ( Int_Pair ( 2, 20 ) );
|
sl@0
|
723 |
m1.insert ( Int_Pair ( 3, 30 ) );
|
sl@0
|
724 |
|
sl@0
|
725 |
mmap m2(m1);
|
sl@0
|
726 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
727 |
CPPUNIT_ASSERT( i1 -> second == 10);
|
sl@0
|
728 |
|
sl@0
|
729 |
mmap m3(10);
|
sl@0
|
730 |
bcount = m3.bucket_count();
|
sl@0
|
731 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
732 |
|
sl@0
|
733 |
mmap::hasher hfn = m1.hash_funct();
|
sl@0
|
734 |
mmap m4(20,hfn);
|
sl@0
|
735 |
bcount = m4.bucket_count();
|
sl@0
|
736 |
CPPUNIT_ASSERT( bcount >= 20);
|
sl@0
|
737 |
|
sl@0
|
738 |
mmap m5(m1.begin(),m2.end());
|
sl@0
|
739 |
CPPUNIT_ASSERT( m5.size() == 3);
|
sl@0
|
740 |
|
sl@0
|
741 |
mmap m6(m1.begin(),m2.end(),30);
|
sl@0
|
742 |
CPPUNIT_ASSERT( m6.size() == 3);
|
sl@0
|
743 |
bcount = m6.bucket_count();
|
sl@0
|
744 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
745 |
|
sl@0
|
746 |
mmap m7(m1.begin(),m2.end(),30,hfn);
|
sl@0
|
747 |
CPPUNIT_ASSERT( m7.size() == 3);
|
sl@0
|
748 |
bcount = m7.bucket_count();
|
sl@0
|
749 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
750 |
|
sl@0
|
751 |
mmap::key_equal cmpfn;
|
sl@0
|
752 |
mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
|
sl@0
|
753 |
|
sl@0
|
754 |
mmap m9(30,hfn,cmpfn);
|
sl@0
|
755 |
}
|
sl@0
|
756 |
__UHEAP_MARKEND;
|
sl@0
|
757 |
}
|
sl@0
|
758 |
|
sl@0
|
759 |
void HashTest::hash_set_cov1()
|
sl@0
|
760 |
{
|
sl@0
|
761 |
__UHEAP_MARK;
|
sl@0
|
762 |
{
|
sl@0
|
763 |
hash_set <int> hm1, hm2;
|
sl@0
|
764 |
hash_set <int>::iterator hm1_Iter;
|
sl@0
|
765 |
hash_set <int>::const_iterator hm1_cIter;
|
sl@0
|
766 |
|
sl@0
|
767 |
hm1.insert ( 10 );
|
sl@0
|
768 |
hm1.insert ( 20 );
|
sl@0
|
769 |
hm1.insert ( 30 );
|
sl@0
|
770 |
hm2.insert ( 300 );
|
sl@0
|
771 |
|
sl@0
|
772 |
hm1.swap( hm2 );
|
sl@0
|
773 |
hm1_Iter = hm1.begin( );
|
sl@0
|
774 |
CPPUNIT_ASSERT( *hm1_Iter == 300);
|
sl@0
|
775 |
hm1_Iter = hm1.end( );
|
sl@0
|
776 |
hm1_cIter = hm1.end( );
|
sl@0
|
777 |
hm1.clear();
|
sl@0
|
778 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
779 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
780 |
}
|
sl@0
|
781 |
{
|
sl@0
|
782 |
hash_set <int> hm1, hm2;
|
sl@0
|
783 |
hash_set <int>::iterator hm1_Iter;
|
sl@0
|
784 |
hash_set <int>::const_iterator hm1_cIter;
|
sl@0
|
785 |
|
sl@0
|
786 |
hm1.insert ( 10 );
|
sl@0
|
787 |
hm1.insert ( 20 );
|
sl@0
|
788 |
hm1.insert ( 30 );
|
sl@0
|
789 |
hm2.insert ( 300 );
|
sl@0
|
790 |
|
sl@0
|
791 |
swap( hm1,hm2 );
|
sl@0
|
792 |
hm1_Iter = hm1.begin( );
|
sl@0
|
793 |
CPPUNIT_ASSERT( *hm1_Iter == 300);
|
sl@0
|
794 |
hm1_Iter = hm1.end( );
|
sl@0
|
795 |
hm1_cIter = hm1.end( );
|
sl@0
|
796 |
hm1.clear();
|
sl@0
|
797 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
798 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
799 |
}
|
sl@0
|
800 |
__UHEAP_MARKEND;
|
sl@0
|
801 |
}
|
sl@0
|
802 |
void HashTest::hash_set_cov2()
|
sl@0
|
803 |
{
|
sl@0
|
804 |
__UHEAP_MARK;
|
sl@0
|
805 |
{
|
sl@0
|
806 |
hash_set <int> hm1;
|
sl@0
|
807 |
int i,bcount;
|
sl@0
|
808 |
|
sl@0
|
809 |
hm1.insert ( 1 );
|
sl@0
|
810 |
i = hm1.size( );
|
sl@0
|
811 |
CPPUNIT_ASSERT( i == 1);
|
sl@0
|
812 |
|
sl@0
|
813 |
i = hm1.max_size(); // for covering the api
|
sl@0
|
814 |
|
sl@0
|
815 |
hm1.insert ( 4 );
|
sl@0
|
816 |
i = hm1.size( );
|
sl@0
|
817 |
CPPUNIT_ASSERT( i == 2);
|
sl@0
|
818 |
hm1.resize(10);
|
sl@0
|
819 |
bcount = hm1.bucket_count();
|
sl@0
|
820 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
821 |
hm1.elems_in_bucket(1);
|
sl@0
|
822 |
}
|
sl@0
|
823 |
{
|
sl@0
|
824 |
typedef hash_multiset<int> mmap;
|
sl@0
|
825 |
mmap m;
|
sl@0
|
826 |
|
sl@0
|
827 |
m.insert ( 10 );
|
sl@0
|
828 |
m.insert ( 20 );
|
sl@0
|
829 |
m.insert ( 30 );
|
sl@0
|
830 |
|
sl@0
|
831 |
std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
|
sl@0
|
832 |
CPPUNIT_ASSERT( *(pair1.first) == 20);
|
sl@0
|
833 |
CPPUNIT_ASSERT( *(pair1.second) == 30);
|
sl@0
|
834 |
// negative test case for equal_range where the key value is not present.
|
sl@0
|
835 |
std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
|
sl@0
|
836 |
CPPUNIT_ASSERT( pair2.first == m.end());
|
sl@0
|
837 |
CPPUNIT_ASSERT( pair2.second == m.end());
|
sl@0
|
838 |
}
|
sl@0
|
839 |
{
|
sl@0
|
840 |
typedef hash_multiset<int> mmap;
|
sl@0
|
841 |
mmap m;
|
sl@0
|
842 |
|
sl@0
|
843 |
m.insert ( 10 );
|
sl@0
|
844 |
m.insert ( 20 );
|
sl@0
|
845 |
m.insert ( 30 );
|
sl@0
|
846 |
|
sl@0
|
847 |
m.erase(m.begin());
|
sl@0
|
848 |
mmap::iterator i1 = m.begin();
|
sl@0
|
849 |
CPPUNIT_ASSERT( *i1 == 20);
|
sl@0
|
850 |
CPPUNIT_ASSERT( m.size() == 2 );
|
sl@0
|
851 |
m.erase(m.begin(),m.end());
|
sl@0
|
852 |
CPPUNIT_ASSERT( m.size() == 0 );
|
sl@0
|
853 |
}
|
sl@0
|
854 |
__UHEAP_MARKEND;
|
sl@0
|
855 |
}
|
sl@0
|
856 |
void HashTest::hash_set_cov3()
|
sl@0
|
857 |
{
|
sl@0
|
858 |
__UHEAP_MARK;
|
sl@0
|
859 |
{
|
sl@0
|
860 |
typedef hash_multiset<int> mmap;
|
sl@0
|
861 |
mmap m;
|
sl@0
|
862 |
|
sl@0
|
863 |
m.insert ( 10 );
|
sl@0
|
864 |
m.insert ( 20 );
|
sl@0
|
865 |
m.insert ( 30 );
|
sl@0
|
866 |
|
sl@0
|
867 |
mmap::iterator i1 = m.find(10);
|
sl@0
|
868 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
869 |
mmap::const_iterator i2 = m.find(30);
|
sl@0
|
870 |
CPPUNIT_ASSERT( *i2 == 30);
|
sl@0
|
871 |
}
|
sl@0
|
872 |
{
|
sl@0
|
873 |
typedef hash_multiset<int> mmap;
|
sl@0
|
874 |
typedef allocator<std::pair<int, int> > Myalloc;
|
sl@0
|
875 |
mmap m;
|
sl@0
|
876 |
|
sl@0
|
877 |
mmap::allocator_type al = m.get_allocator();
|
sl@0
|
878 |
CPPUNIT_ASSERT ((al == Myalloc()) == true);
|
sl@0
|
879 |
|
sl@0
|
880 |
mmap::hasher hfn = m.hash_funct(); // returns the hasher function
|
sl@0
|
881 |
}
|
sl@0
|
882 |
{
|
sl@0
|
883 |
typedef hash_multiset<int> mmap;
|
sl@0
|
884 |
mmap m1,m2;
|
sl@0
|
885 |
|
sl@0
|
886 |
m1.insert ( 10 );
|
sl@0
|
887 |
m1.insert ( 20 );
|
sl@0
|
888 |
m1.insert ( 30 );
|
sl@0
|
889 |
|
sl@0
|
890 |
m2.insert ( m1.begin(),m1.end());
|
sl@0
|
891 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
892 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
893 |
}
|
sl@0
|
894 |
|
sl@0
|
895 |
{
|
sl@0
|
896 |
typedef hash_set<int> mmap;
|
sl@0
|
897 |
mmap m;
|
sl@0
|
898 |
|
sl@0
|
899 |
m.insert ( 10 );
|
sl@0
|
900 |
m.insert ( 20 );
|
sl@0
|
901 |
m.insert ( 30 );
|
sl@0
|
902 |
|
sl@0
|
903 |
std::pair<mmap::iterator, mmap::iterator> pair1 = m.equal_range(20);
|
sl@0
|
904 |
CPPUNIT_ASSERT( *(pair1.first) == 20);
|
sl@0
|
905 |
CPPUNIT_ASSERT( *(pair1.second) == 30);
|
sl@0
|
906 |
// negative test case for equal_range where the key value is not present.
|
sl@0
|
907 |
std::pair<mmap::const_iterator, mmap::const_iterator> pair2 = m.equal_range(40);
|
sl@0
|
908 |
CPPUNIT_ASSERT( pair2.first == m.end());
|
sl@0
|
909 |
CPPUNIT_ASSERT( pair2.second == m.end()); }
|
sl@0
|
910 |
__UHEAP_MARKEND;
|
sl@0
|
911 |
}
|
sl@0
|
912 |
void HashTest::hash_set_cov4()
|
sl@0
|
913 |
{
|
sl@0
|
914 |
__UHEAP_MARK;
|
sl@0
|
915 |
{
|
sl@0
|
916 |
typedef hash_set<int> mmap;
|
sl@0
|
917 |
mmap m;
|
sl@0
|
918 |
|
sl@0
|
919 |
m.insert ( 10 );
|
sl@0
|
920 |
m.insert ( 20 );
|
sl@0
|
921 |
m.insert ( 30 );
|
sl@0
|
922 |
|
sl@0
|
923 |
m.erase(m.begin());
|
sl@0
|
924 |
mmap::iterator i1 = m.begin();
|
sl@0
|
925 |
CPPUNIT_ASSERT( *i1 == 20);
|
sl@0
|
926 |
CPPUNIT_ASSERT( m.size() == 2 );
|
sl@0
|
927 |
m.erase(m.begin(),m.end());
|
sl@0
|
928 |
CPPUNIT_ASSERT( m.size() == 0 );
|
sl@0
|
929 |
}
|
sl@0
|
930 |
{
|
sl@0
|
931 |
typedef hash_set<int> mmap;
|
sl@0
|
932 |
mmap m;
|
sl@0
|
933 |
|
sl@0
|
934 |
m.insert ( 10 );
|
sl@0
|
935 |
m.insert ( 20 );
|
sl@0
|
936 |
m.insert ( 30 );
|
sl@0
|
937 |
|
sl@0
|
938 |
mmap::iterator i1 = m.find(10);
|
sl@0
|
939 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
940 |
mmap::const_iterator i2 = m.find(30);
|
sl@0
|
941 |
CPPUNIT_ASSERT( *i2 == 30);
|
sl@0
|
942 |
}
|
sl@0
|
943 |
{
|
sl@0
|
944 |
typedef hash_set<int> mmap;
|
sl@0
|
945 |
typedef allocator<std::pair<int, int> > Myalloc;
|
sl@0
|
946 |
mmap m;
|
sl@0
|
947 |
|
sl@0
|
948 |
mmap::allocator_type al = m.get_allocator();
|
sl@0
|
949 |
CPPUNIT_ASSERT ((al == Myalloc()) == true);
|
sl@0
|
950 |
|
sl@0
|
951 |
mmap::hasher hfn = m.hash_funct(); // returns the hasher function
|
sl@0
|
952 |
}
|
sl@0
|
953 |
__UHEAP_MARKEND;
|
sl@0
|
954 |
}
|
sl@0
|
955 |
void HashTest::hash_set_cov5()
|
sl@0
|
956 |
{
|
sl@0
|
957 |
__UHEAP_MARK;
|
sl@0
|
958 |
{
|
sl@0
|
959 |
typedef hash_set<int> mmap;
|
sl@0
|
960 |
mmap m1,m2;
|
sl@0
|
961 |
|
sl@0
|
962 |
m1.insert ( 10 );
|
sl@0
|
963 |
m1.insert ( 20 );
|
sl@0
|
964 |
m1.insert ( 30 );
|
sl@0
|
965 |
|
sl@0
|
966 |
m2.insert ( m1.begin(),m1.end());
|
sl@0
|
967 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
968 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
969 |
}
|
sl@0
|
970 |
{
|
sl@0
|
971 |
typedef hash_set<char> mmap;
|
sl@0
|
972 |
mmap c1;
|
sl@0
|
973 |
mmap::key_equal cmpfn = c1.key_eq();
|
sl@0
|
974 |
CPPUNIT_ASSERT( cmpfn('a','a') == true);
|
sl@0
|
975 |
|
sl@0
|
976 |
c1.max_bucket_count(); // for covering the api
|
sl@0
|
977 |
}
|
sl@0
|
978 |
{
|
sl@0
|
979 |
typedef hash_set<int> mmap;
|
sl@0
|
980 |
mmap m1;
|
sl@0
|
981 |
|
sl@0
|
982 |
m1.insert_noresize ( 10 );
|
sl@0
|
983 |
m1.insert_noresize ( 20 );
|
sl@0
|
984 |
m1.insert_noresize ( 30 );
|
sl@0
|
985 |
|
sl@0
|
986 |
mmap::iterator i1 = m1.begin();
|
sl@0
|
987 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
988 |
}
|
sl@0
|
989 |
{
|
sl@0
|
990 |
typedef hash_set<int> mmap;
|
sl@0
|
991 |
mmap m1;
|
sl@0
|
992 |
int bcount;
|
sl@0
|
993 |
|
sl@0
|
994 |
m1.insert ( 10 );
|
sl@0
|
995 |
m1.insert ( 20 );
|
sl@0
|
996 |
m1.insert ( 30 );
|
sl@0
|
997 |
|
sl@0
|
998 |
mmap m2(m1);
|
sl@0
|
999 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
1000 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
1001 |
|
sl@0
|
1002 |
mmap m3(10);
|
sl@0
|
1003 |
bcount = m3.bucket_count();
|
sl@0
|
1004 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
1005 |
|
sl@0
|
1006 |
mmap::hasher hfn = m1.hash_funct();
|
sl@0
|
1007 |
mmap m4(20,hfn);
|
sl@0
|
1008 |
bcount = m4.bucket_count();
|
sl@0
|
1009 |
CPPUNIT_ASSERT( bcount >= 20);
|
sl@0
|
1010 |
|
sl@0
|
1011 |
mmap m5(m1.begin(),m2.end());
|
sl@0
|
1012 |
CPPUNIT_ASSERT( m5.size() == 3);
|
sl@0
|
1013 |
|
sl@0
|
1014 |
mmap m6(m1.begin(),m2.end(),30);
|
sl@0
|
1015 |
CPPUNIT_ASSERT( m6.size() == 3);
|
sl@0
|
1016 |
bcount = m6.bucket_count();
|
sl@0
|
1017 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
1018 |
|
sl@0
|
1019 |
mmap m7(m1.begin(),m2.end(),30,hfn);
|
sl@0
|
1020 |
CPPUNIT_ASSERT( m7.size() == 3);
|
sl@0
|
1021 |
bcount = m7.bucket_count();
|
sl@0
|
1022 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
1023 |
|
sl@0
|
1024 |
mmap::key_equal cmpfn;// = c1.key_eq();
|
sl@0
|
1025 |
mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
|
sl@0
|
1026 |
|
sl@0
|
1027 |
mmap m9(30,hfn,cmpfn);
|
sl@0
|
1028 |
}
|
sl@0
|
1029 |
__UHEAP_MARKEND;
|
sl@0
|
1030 |
}
|
sl@0
|
1031 |
void HashTest::hash_set_cov6()
|
sl@0
|
1032 |
{
|
sl@0
|
1033 |
__UHEAP_MARK;
|
sl@0
|
1034 |
{
|
sl@0
|
1035 |
typedef hash_set<int> mmap;
|
sl@0
|
1036 |
mmap m1;
|
sl@0
|
1037 |
|
sl@0
|
1038 |
m1.insert ( 10 );
|
sl@0
|
1039 |
m1.insert ( 20 );
|
sl@0
|
1040 |
m1.insert ( 30 );
|
sl@0
|
1041 |
|
sl@0
|
1042 |
CPPUNIT_ASSERT( m1.count(10) == 1);
|
sl@0
|
1043 |
CPPUNIT_ASSERT( m1.erase(10) == 1);
|
sl@0
|
1044 |
CPPUNIT_ASSERT( m1.count(10) == 0);
|
sl@0
|
1045 |
}
|
sl@0
|
1046 |
{
|
sl@0
|
1047 |
hash_set <int> hm1;
|
sl@0
|
1048 |
hash_set <int>::iterator hm1_Iter;
|
sl@0
|
1049 |
hm1.insert ( 10 );
|
sl@0
|
1050 |
hm1.insert ( 20 );
|
sl@0
|
1051 |
hm1.insert ( 30 );
|
sl@0
|
1052 |
hm1_Iter = hm1.begin( );
|
sl@0
|
1053 |
CPPUNIT_ASSERT( *hm1_Iter == 10);
|
sl@0
|
1054 |
hm1_Iter ++ ;
|
sl@0
|
1055 |
CPPUNIT_ASSERT( *hm1_Iter == 20);
|
sl@0
|
1056 |
hm1_Iter ++ ;
|
sl@0
|
1057 |
CPPUNIT_ASSERT( *hm1_Iter == 30);
|
sl@0
|
1058 |
|
sl@0
|
1059 |
}
|
sl@0
|
1060 |
__UHEAP_MARKEND;
|
sl@0
|
1061 |
}
|
sl@0
|
1062 |
|
sl@0
|
1063 |
void HashTest::hash_multiset_cov1()
|
sl@0
|
1064 |
{
|
sl@0
|
1065 |
__UHEAP_MARK;
|
sl@0
|
1066 |
{
|
sl@0
|
1067 |
hash_multiset <int> hm1, hm2;
|
sl@0
|
1068 |
hash_multiset <int>::iterator hm1_Iter;
|
sl@0
|
1069 |
hash_multiset <int>::const_iterator hm1_cIter;
|
sl@0
|
1070 |
|
sl@0
|
1071 |
hm1.insert ( 10 );
|
sl@0
|
1072 |
hm1.insert ( 20 );
|
sl@0
|
1073 |
hm1.insert ( 30 );
|
sl@0
|
1074 |
hm2.insert ( 300 );
|
sl@0
|
1075 |
|
sl@0
|
1076 |
hm1.swap( hm2 );
|
sl@0
|
1077 |
hm1_Iter = hm1.begin( );
|
sl@0
|
1078 |
CPPUNIT_ASSERT( *hm1_Iter== 300);
|
sl@0
|
1079 |
hm1_Iter = hm1.end( );
|
sl@0
|
1080 |
hm1_cIter = hm1.end( );
|
sl@0
|
1081 |
hm1.clear();
|
sl@0
|
1082 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
1083 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
1084 |
}
|
sl@0
|
1085 |
{
|
sl@0
|
1086 |
hash_multiset <int> hm1, hm2;
|
sl@0
|
1087 |
hash_multiset <int>::iterator hm1_Iter;
|
sl@0
|
1088 |
hash_multiset <int>::const_iterator hm1_cIter;
|
sl@0
|
1089 |
|
sl@0
|
1090 |
hm1.insert ( 10 );
|
sl@0
|
1091 |
hm1.insert ( 20 );
|
sl@0
|
1092 |
hm1.insert ( 30 );
|
sl@0
|
1093 |
hm2.insert ( 300 );
|
sl@0
|
1094 |
|
sl@0
|
1095 |
swap( hm1,hm2 );
|
sl@0
|
1096 |
hm1_Iter = hm1.begin( );
|
sl@0
|
1097 |
CPPUNIT_ASSERT( *hm1_Iter== 300);
|
sl@0
|
1098 |
hm1_Iter = hm1.end( );
|
sl@0
|
1099 |
hm1_cIter = hm1.end( );
|
sl@0
|
1100 |
hm1.clear();
|
sl@0
|
1101 |
CPPUNIT_ASSERT( hm1.size() == 0 );
|
sl@0
|
1102 |
CPPUNIT_ASSERT( hm1.empty() == true );
|
sl@0
|
1103 |
}
|
sl@0
|
1104 |
__UHEAP_MARKEND;
|
sl@0
|
1105 |
}
|
sl@0
|
1106 |
void HashTest::hash_multiset_cov2()
|
sl@0
|
1107 |
{
|
sl@0
|
1108 |
__UHEAP_MARK;
|
sl@0
|
1109 |
{
|
sl@0
|
1110 |
hash_multiset <int> hm1;
|
sl@0
|
1111 |
int i,bcount;
|
sl@0
|
1112 |
|
sl@0
|
1113 |
hm1.insert ( 1 );
|
sl@0
|
1114 |
i = hm1.size( );
|
sl@0
|
1115 |
CPPUNIT_ASSERT( i == 1);
|
sl@0
|
1116 |
|
sl@0
|
1117 |
i = hm1.max_size(); // for covering the api
|
sl@0
|
1118 |
|
sl@0
|
1119 |
hm1.insert ( 4 );
|
sl@0
|
1120 |
i = hm1.size( );
|
sl@0
|
1121 |
CPPUNIT_ASSERT( i == 2);
|
sl@0
|
1122 |
hm1.resize(10);
|
sl@0
|
1123 |
bcount = hm1.bucket_count();
|
sl@0
|
1124 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
1125 |
hm1.elems_in_bucket(1);
|
sl@0
|
1126 |
}
|
sl@0
|
1127 |
{
|
sl@0
|
1128 |
typedef hash_multiset<int> mmap;
|
sl@0
|
1129 |
mmap m1;
|
sl@0
|
1130 |
|
sl@0
|
1131 |
m1.insert_noresize ( 10 );
|
sl@0
|
1132 |
m1.insert_noresize ( 20 );
|
sl@0
|
1133 |
m1.insert_noresize ( 30 );
|
sl@0
|
1134 |
|
sl@0
|
1135 |
mmap::iterator i1 = m1.begin();
|
sl@0
|
1136 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
1137 |
}
|
sl@0
|
1138 |
{
|
sl@0
|
1139 |
typedef hash_multiset<char> mmap;
|
sl@0
|
1140 |
mmap c1;
|
sl@0
|
1141 |
mmap::key_equal cmpfn = c1.key_eq();
|
sl@0
|
1142 |
CPPUNIT_ASSERT( cmpfn('a','a') == true);
|
sl@0
|
1143 |
|
sl@0
|
1144 |
c1.max_bucket_count(); // for covering the api
|
sl@0
|
1145 |
}
|
sl@0
|
1146 |
__UHEAP_MARKEND;
|
sl@0
|
1147 |
}
|
sl@0
|
1148 |
void HashTest::hash_multiset_cov3()
|
sl@0
|
1149 |
{
|
sl@0
|
1150 |
__UHEAP_MARK;
|
sl@0
|
1151 |
{
|
sl@0
|
1152 |
typedef hash_multiset<int> mmap;
|
sl@0
|
1153 |
mmap m1;
|
sl@0
|
1154 |
int bcount;
|
sl@0
|
1155 |
|
sl@0
|
1156 |
m1.insert ( 10 );
|
sl@0
|
1157 |
m1.insert ( 20 );
|
sl@0
|
1158 |
m1.insert ( 30 );
|
sl@0
|
1159 |
|
sl@0
|
1160 |
mmap m2(m1);
|
sl@0
|
1161 |
mmap::iterator i1 = m2.begin();
|
sl@0
|
1162 |
CPPUNIT_ASSERT( *i1 == 10);
|
sl@0
|
1163 |
|
sl@0
|
1164 |
mmap m3(10);
|
sl@0
|
1165 |
bcount = m3.bucket_count();
|
sl@0
|
1166 |
CPPUNIT_ASSERT( bcount >= 10);
|
sl@0
|
1167 |
|
sl@0
|
1168 |
mmap::hasher hfn = m1.hash_funct();
|
sl@0
|
1169 |
mmap m4(20,hfn);
|
sl@0
|
1170 |
bcount = m4.bucket_count();
|
sl@0
|
1171 |
CPPUNIT_ASSERT( bcount >= 20);
|
sl@0
|
1172 |
|
sl@0
|
1173 |
mmap m5(m1.begin(),m2.end());
|
sl@0
|
1174 |
CPPUNIT_ASSERT( m5.size() == 3);
|
sl@0
|
1175 |
|
sl@0
|
1176 |
mmap m6(m1.begin(),m2.end(),30);
|
sl@0
|
1177 |
CPPUNIT_ASSERT( m6.size() == 3);
|
sl@0
|
1178 |
bcount = m6.bucket_count();
|
sl@0
|
1179 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
1180 |
|
sl@0
|
1181 |
mmap m7(m1.begin(),m2.end(),30,hfn);
|
sl@0
|
1182 |
CPPUNIT_ASSERT( m7.size() == 3);
|
sl@0
|
1183 |
bcount = m7.bucket_count();
|
sl@0
|
1184 |
CPPUNIT_ASSERT( bcount >= 30);
|
sl@0
|
1185 |
|
sl@0
|
1186 |
mmap::key_equal cmpfn;// = c1.key_eq();
|
sl@0
|
1187 |
mmap m8(m1.begin(),m2.end(),30,hfn,cmpfn);
|
sl@0
|
1188 |
|
sl@0
|
1189 |
mmap m9(30,hfn,cmpfn);
|
sl@0
|
1190 |
}
|
sl@0
|
1191 |
__UHEAP_MARKEND;
|
sl@0
|
1192 |
}
|