sl@0
|
1 |
// Copyright (c) 1994-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 the License "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 |
// e32test\buffer\int_arr.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include <e32math.h>
|
sl@0
|
20 |
|
sl@0
|
21 |
#define NUM_TESTS 500
|
sl@0
|
22 |
|
sl@0
|
23 |
GLREF_D RTest test;
|
sl@0
|
24 |
GLREF_C TInt Random();
|
sl@0
|
25 |
|
sl@0
|
26 |
struct SInt
|
sl@0
|
27 |
{
|
sl@0
|
28 |
SInt(TInt a) {i=a;}
|
sl@0
|
29 |
operator TInt() {return i;}
|
sl@0
|
30 |
|
sl@0
|
31 |
TInt i;
|
sl@0
|
32 |
};
|
sl@0
|
33 |
|
sl@0
|
34 |
LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
TInt n;
|
sl@0
|
37 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
38 |
{
|
sl@0
|
39 |
RArray<TInt> a;
|
sl@0
|
40 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
41 |
if (!pA)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
a.Close();
|
sl@0
|
44 |
return -65535;
|
sl@0
|
45 |
}
|
sl@0
|
46 |
TInt i;
|
sl@0
|
47 |
for (i=0; i<aCount; i++)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
TInt x=Random()&aRange;
|
sl@0
|
50 |
a.Append(x);
|
sl@0
|
51 |
pA[i]=x;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
if (a.Count()!=aCount)
|
sl@0
|
54 |
{
|
sl@0
|
55 |
a.Close();
|
sl@0
|
56 |
return -1;
|
sl@0
|
57 |
}
|
sl@0
|
58 |
for (i=0; i<aCount; i++)
|
sl@0
|
59 |
{
|
sl@0
|
60 |
if (a[i]!=pA[i])
|
sl@0
|
61 |
{
|
sl@0
|
62 |
a.Close();
|
sl@0
|
63 |
return -2;
|
sl@0
|
64 |
}
|
sl@0
|
65 |
TInt x=Random()&aRange;
|
sl@0
|
66 |
a[i]=x;
|
sl@0
|
67 |
pA[i]=x;
|
sl@0
|
68 |
}
|
sl@0
|
69 |
if (a.Count()!=aCount)
|
sl@0
|
70 |
{
|
sl@0
|
71 |
a.Close();
|
sl@0
|
72 |
return -3;
|
sl@0
|
73 |
}
|
sl@0
|
74 |
for (i=0; i<aCount; i++)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
if (a[i]!=pA[i])
|
sl@0
|
77 |
{
|
sl@0
|
78 |
a.Close();
|
sl@0
|
79 |
return -4;
|
sl@0
|
80 |
}
|
sl@0
|
81 |
}
|
sl@0
|
82 |
delete pA;
|
sl@0
|
83 |
a.Close();
|
sl@0
|
84 |
}
|
sl@0
|
85 |
return KErrNone;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
LOCAL_C TInt IntRemoveTest()
|
sl@0
|
89 |
{
|
sl@0
|
90 |
TInt m=32;
|
sl@0
|
91 |
TInt n=m*m+1;
|
sl@0
|
92 |
RArray<TInt> a;
|
sl@0
|
93 |
TInt i;
|
sl@0
|
94 |
for (i=0; i<n; i++)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
a.Append(i);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
TInt p=2;
|
sl@0
|
99 |
for (i=2; i<=m; i++)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
TInt j;
|
sl@0
|
102 |
for (j=0; j<(2*i-2); j++)
|
sl@0
|
103 |
{
|
sl@0
|
104 |
a.Remove(p);
|
sl@0
|
105 |
}
|
sl@0
|
106 |
p++;
|
sl@0
|
107 |
}
|
sl@0
|
108 |
if (a.Count()!=m+1)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
a.Close();
|
sl@0
|
111 |
return -1;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
for (i=0; i<m; i++)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
if (a[i]!=i*i)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
a.Close();
|
sl@0
|
118 |
return -2;
|
sl@0
|
119 |
}
|
sl@0
|
120 |
}
|
sl@0
|
121 |
a.Close();
|
sl@0
|
122 |
return KErrNone;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|
sl@0
|
125 |
LOCAL_C TInt IntFindTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
TInt n;
|
sl@0
|
128 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
RArray<TInt> a;
|
sl@0
|
131 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
132 |
if (!pA)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
a.Close();
|
sl@0
|
135 |
return -65535;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
TInt i;
|
sl@0
|
138 |
for (i=0; i<aCount; i++)
|
sl@0
|
139 |
{
|
sl@0
|
140 |
TInt x=Random()&aRange;
|
sl@0
|
141 |
a.Append(x);
|
sl@0
|
142 |
pA[i]=x;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
if (a.Count()!=aCount)
|
sl@0
|
145 |
{
|
sl@0
|
146 |
a.Close();
|
sl@0
|
147 |
return -1;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
for (i=0; i<aCount; i++)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
TInt r=a.Find(pA[i]);
|
sl@0
|
152 |
if (r<0 || pA[r]!=pA[i] || r>i)
|
sl@0
|
153 |
{
|
sl@0
|
154 |
a.Close();
|
sl@0
|
155 |
return -2;
|
sl@0
|
156 |
}
|
sl@0
|
157 |
TInt x=Random()&aRange;
|
sl@0
|
158 |
r=a.Find(x);
|
sl@0
|
159 |
if (r<0)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
TInt j;
|
sl@0
|
162 |
for (j=0; j<aCount; j++)
|
sl@0
|
163 |
{
|
sl@0
|
164 |
if (pA[j]==x)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
a.Close();
|
sl@0
|
167 |
return -3;
|
sl@0
|
168 |
}
|
sl@0
|
169 |
}
|
sl@0
|
170 |
}
|
sl@0
|
171 |
else if (pA[r]!=x)
|
sl@0
|
172 |
{
|
sl@0
|
173 |
a.Close();
|
sl@0
|
174 |
return -4;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
else
|
sl@0
|
177 |
{
|
sl@0
|
178 |
TInt j;
|
sl@0
|
179 |
for (j=0; j<r; j++)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
if (pA[j]==x)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
a.Close();
|
sl@0
|
184 |
return -5;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
}
|
sl@0
|
187 |
}
|
sl@0
|
188 |
}
|
sl@0
|
189 |
delete pA;
|
sl@0
|
190 |
a.Close();
|
sl@0
|
191 |
}
|
sl@0
|
192 |
return KErrNone;
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
LOCAL_C TInt IntFindInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
196 |
// require aRange*aCount<2^32
|
sl@0
|
197 |
{
|
sl@0
|
198 |
TInt n;
|
sl@0
|
199 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
200 |
{
|
sl@0
|
201 |
RArray<TInt> a;
|
sl@0
|
202 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
203 |
if (!pA)
|
sl@0
|
204 |
{
|
sl@0
|
205 |
a.Close();
|
sl@0
|
206 |
return -65535;
|
sl@0
|
207 |
}
|
sl@0
|
208 |
TInt i=0;
|
sl@0
|
209 |
TInt y=-256;
|
sl@0
|
210 |
for(i=0; i<aCount; i++)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
TInt x=Random()&aRange; // this is always >=0
|
sl@0
|
213 |
a.Append(y);
|
sl@0
|
214 |
pA[i]=y;
|
sl@0
|
215 |
y+=x;
|
sl@0
|
216 |
}
|
sl@0
|
217 |
if (a.Count()!=aCount)
|
sl@0
|
218 |
{
|
sl@0
|
219 |
a.Close();
|
sl@0
|
220 |
return -1;
|
sl@0
|
221 |
}
|
sl@0
|
222 |
for (i=0; i<aCount; i++)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
TInt r=a.FindInOrder(pA[i]);
|
sl@0
|
225 |
if (r<0 || pA[r]!=pA[i])
|
sl@0
|
226 |
{
|
sl@0
|
227 |
a.Close();
|
sl@0
|
228 |
return -2;
|
sl@0
|
229 |
}
|
sl@0
|
230 |
TInt x=Random()&aRange;
|
sl@0
|
231 |
r=a.FindInOrder(x);
|
sl@0
|
232 |
if (r<0)
|
sl@0
|
233 |
{
|
sl@0
|
234 |
TInt j;
|
sl@0
|
235 |
for (j=0; j<aCount; j++)
|
sl@0
|
236 |
{
|
sl@0
|
237 |
if (pA[j]==x)
|
sl@0
|
238 |
{
|
sl@0
|
239 |
a.Close();
|
sl@0
|
240 |
return -3;
|
sl@0
|
241 |
}
|
sl@0
|
242 |
}
|
sl@0
|
243 |
}
|
sl@0
|
244 |
else if (pA[r]!=x)
|
sl@0
|
245 |
{
|
sl@0
|
246 |
a.Close();
|
sl@0
|
247 |
return -4;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
}
|
sl@0
|
250 |
delete pA;
|
sl@0
|
251 |
a.Close();
|
sl@0
|
252 |
}
|
sl@0
|
253 |
return KErrNone;
|
sl@0
|
254 |
}
|
sl@0
|
255 |
|
sl@0
|
256 |
LOCAL_C TInt IntFindInOrderTest2()
|
sl@0
|
257 |
{
|
sl@0
|
258 |
TInt i;
|
sl@0
|
259 |
RArray<TInt> sq;
|
sl@0
|
260 |
for (i=0; i<1024; i++)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
TInt j=i*i;
|
sl@0
|
263 |
sq.Append(j);
|
sl@0
|
264 |
}
|
sl@0
|
265 |
for (i=0; i<10000; i++)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
TInt x=Random()&1023;
|
sl@0
|
268 |
TInt y=x*x;
|
sl@0
|
269 |
TInt r=sq.FindInOrder(y);
|
sl@0
|
270 |
if (r!=x)
|
sl@0
|
271 |
{
|
sl@0
|
272 |
sq.Close();
|
sl@0
|
273 |
return -1;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
}
|
sl@0
|
276 |
sq.Close();
|
sl@0
|
277 |
return 0;
|
sl@0
|
278 |
}
|
sl@0
|
279 |
|
sl@0
|
280 |
LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
TInt n;
|
sl@0
|
283 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
RArray<TInt> a;
|
sl@0
|
286 |
RArray<TInt> b;
|
sl@0
|
287 |
RArray<TInt> c;
|
sl@0
|
288 |
TInt i;
|
sl@0
|
289 |
TInt cc=0;
|
sl@0
|
290 |
for (i=0; i<aCount; i++)
|
sl@0
|
291 |
{
|
sl@0
|
292 |
TInt x=Random()&aRange;
|
sl@0
|
293 |
a.Append(x);
|
sl@0
|
294 |
b.InsertInOrderAllowRepeats(x);
|
sl@0
|
295 |
TInt r=c.InsertInOrder(x);
|
sl@0
|
296 |
if (r==KErrNone)
|
sl@0
|
297 |
cc++;
|
sl@0
|
298 |
}
|
sl@0
|
299 |
if (a.Count()!=aCount)
|
sl@0
|
300 |
{
|
sl@0
|
301 |
a.Close();
|
sl@0
|
302 |
b.Close();
|
sl@0
|
303 |
c.Close();
|
sl@0
|
304 |
return -1;
|
sl@0
|
305 |
}
|
sl@0
|
306 |
if (b.Count()!=aCount)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
a.Close();
|
sl@0
|
309 |
b.Close();
|
sl@0
|
310 |
c.Close();
|
sl@0
|
311 |
return -2;
|
sl@0
|
312 |
}
|
sl@0
|
313 |
for (i=0; i<aCount-1; i++)
|
sl@0
|
314 |
{
|
sl@0
|
315 |
if (b[i]>b[i+1])
|
sl@0
|
316 |
{
|
sl@0
|
317 |
a.Close();
|
sl@0
|
318 |
b.Close();
|
sl@0
|
319 |
c.Close();
|
sl@0
|
320 |
return -3;
|
sl@0
|
321 |
}
|
sl@0
|
322 |
}
|
sl@0
|
323 |
for (i=0; i<aCount; i++)
|
sl@0
|
324 |
{
|
sl@0
|
325 |
if (a.Find(b[i])<0)
|
sl@0
|
326 |
{
|
sl@0
|
327 |
a.Close();
|
sl@0
|
328 |
b.Close();
|
sl@0
|
329 |
c.Close();
|
sl@0
|
330 |
return -4;
|
sl@0
|
331 |
}
|
sl@0
|
332 |
if (b.Find(a[i])<0)
|
sl@0
|
333 |
{
|
sl@0
|
334 |
a.Close();
|
sl@0
|
335 |
b.Close();
|
sl@0
|
336 |
c.Close();
|
sl@0
|
337 |
return -5;
|
sl@0
|
338 |
}
|
sl@0
|
339 |
if (c.Find(a[i])<0)
|
sl@0
|
340 |
{
|
sl@0
|
341 |
a.Close();
|
sl@0
|
342 |
b.Close();
|
sl@0
|
343 |
c.Close();
|
sl@0
|
344 |
return -6;
|
sl@0
|
345 |
}
|
sl@0
|
346 |
}
|
sl@0
|
347 |
if (c.Count()!=cc)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
a.Close();
|
sl@0
|
350 |
b.Close();
|
sl@0
|
351 |
c.Close();
|
sl@0
|
352 |
return -7;
|
sl@0
|
353 |
}
|
sl@0
|
354 |
for (i=0; i<c.Count()-1; i++)
|
sl@0
|
355 |
{
|
sl@0
|
356 |
if (c[i]>=c[i+1])
|
sl@0
|
357 |
{
|
sl@0
|
358 |
a.Close();
|
sl@0
|
359 |
b.Close();
|
sl@0
|
360 |
c.Close();
|
sl@0
|
361 |
return -8;
|
sl@0
|
362 |
}
|
sl@0
|
363 |
if (a.Find(c[i])<0)
|
sl@0
|
364 |
{
|
sl@0
|
365 |
a.Close();
|
sl@0
|
366 |
b.Close();
|
sl@0
|
367 |
c.Close();
|
sl@0
|
368 |
return -9;
|
sl@0
|
369 |
}
|
sl@0
|
370 |
}
|
sl@0
|
371 |
a.Close();
|
sl@0
|
372 |
b.Close();
|
sl@0
|
373 |
c.Close();
|
sl@0
|
374 |
}
|
sl@0
|
375 |
return KErrNone;
|
sl@0
|
376 |
}
|
sl@0
|
377 |
|
sl@0
|
378 |
LOCAL_C TInt IntInsertInOrderTest2()
|
sl@0
|
379 |
{
|
sl@0
|
380 |
TInt i;
|
sl@0
|
381 |
RArray<TInt> sq;
|
sl@0
|
382 |
for (i=0; i<1024; i++)
|
sl@0
|
383 |
{
|
sl@0
|
384 |
TInt j=i*i;
|
sl@0
|
385 |
sq.InsertInOrder(j);
|
sl@0
|
386 |
sq.InsertInOrder(-j);
|
sl@0
|
387 |
}
|
sl@0
|
388 |
if (sq.Count()!=2047)
|
sl@0
|
389 |
{
|
sl@0
|
390 |
sq.Close();
|
sl@0
|
391 |
return -1;
|
sl@0
|
392 |
}
|
sl@0
|
393 |
for (i=0; i<2047; i++)
|
sl@0
|
394 |
{
|
sl@0
|
395 |
TInt y=0;
|
sl@0
|
396 |
if (i<1023)
|
sl@0
|
397 |
y=-(1023-i)*(1023-i);
|
sl@0
|
398 |
else if (i==1023)
|
sl@0
|
399 |
y=0;
|
sl@0
|
400 |
else if (i>1023)
|
sl@0
|
401 |
y=(i-1023)*(i-1023);
|
sl@0
|
402 |
if (sq[i]!=y)
|
sl@0
|
403 |
{
|
sl@0
|
404 |
sq.Close();
|
sl@0
|
405 |
return -2;
|
sl@0
|
406 |
}
|
sl@0
|
407 |
}
|
sl@0
|
408 |
sq.Close();
|
sl@0
|
409 |
return 0;
|
sl@0
|
410 |
}
|
sl@0
|
411 |
|
sl@0
|
412 |
LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
TInt n;
|
sl@0
|
415 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
416 |
{
|
sl@0
|
417 |
RArray<TInt> a;
|
sl@0
|
418 |
RArray<TInt> b;
|
sl@0
|
419 |
TInt i;
|
sl@0
|
420 |
for (i=0; i<aCount; i++)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
TInt x=Random()&aRange;
|
sl@0
|
423 |
a.Append(x);
|
sl@0
|
424 |
b.InsertInOrderAllowRepeats(x);
|
sl@0
|
425 |
}
|
sl@0
|
426 |
a.Sort();
|
sl@0
|
427 |
if (a.Count()!=aCount)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
a.Close();
|
sl@0
|
430 |
b.Close();
|
sl@0
|
431 |
return -1;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
if (b.Count()!=aCount)
|
sl@0
|
434 |
{
|
sl@0
|
435 |
a.Close();
|
sl@0
|
436 |
b.Close();
|
sl@0
|
437 |
return -2;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
for (i=0; i<aCount; i++)
|
sl@0
|
440 |
{
|
sl@0
|
441 |
if (a[i]!=b[i])
|
sl@0
|
442 |
{
|
sl@0
|
443 |
a.Close();
|
sl@0
|
444 |
b.Close();
|
sl@0
|
445 |
return -3;
|
sl@0
|
446 |
}
|
sl@0
|
447 |
}
|
sl@0
|
448 |
a.Close();
|
sl@0
|
449 |
b.Close();
|
sl@0
|
450 |
}
|
sl@0
|
451 |
return KErrNone;
|
sl@0
|
452 |
}
|
sl@0
|
453 |
|
sl@0
|
454 |
LOCAL_C TInt SIntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
TInt n;
|
sl@0
|
457 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
RArray<SInt> a;
|
sl@0
|
460 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
461 |
if (!pA)
|
sl@0
|
462 |
{
|
sl@0
|
463 |
a.Close();
|
sl@0
|
464 |
return -65535;
|
sl@0
|
465 |
}
|
sl@0
|
466 |
TInt i;
|
sl@0
|
467 |
for (i=0; i<aCount; i++)
|
sl@0
|
468 |
{
|
sl@0
|
469 |
TInt x=Random()&aRange;
|
sl@0
|
470 |
a.Append(x);
|
sl@0
|
471 |
pA[i]=x;
|
sl@0
|
472 |
}
|
sl@0
|
473 |
if (a.Count()!=aCount)
|
sl@0
|
474 |
{
|
sl@0
|
475 |
a.Close();
|
sl@0
|
476 |
return -1;
|
sl@0
|
477 |
}
|
sl@0
|
478 |
for (i=0; i<aCount; i++)
|
sl@0
|
479 |
{
|
sl@0
|
480 |
if (a[i]!=pA[i])
|
sl@0
|
481 |
{
|
sl@0
|
482 |
a.Close();
|
sl@0
|
483 |
return -2;
|
sl@0
|
484 |
}
|
sl@0
|
485 |
TInt x=Random()&aRange;
|
sl@0
|
486 |
a[i]=x;
|
sl@0
|
487 |
pA[i]=x;
|
sl@0
|
488 |
}
|
sl@0
|
489 |
if (a.Count()!=aCount)
|
sl@0
|
490 |
{
|
sl@0
|
491 |
a.Close();
|
sl@0
|
492 |
return -3;
|
sl@0
|
493 |
}
|
sl@0
|
494 |
for (i=0; i<aCount; i++)
|
sl@0
|
495 |
{
|
sl@0
|
496 |
if (a[i]!=pA[i])
|
sl@0
|
497 |
{
|
sl@0
|
498 |
a.Close();
|
sl@0
|
499 |
return -4;
|
sl@0
|
500 |
}
|
sl@0
|
501 |
}
|
sl@0
|
502 |
delete pA;
|
sl@0
|
503 |
a.Close();
|
sl@0
|
504 |
}
|
sl@0
|
505 |
return KErrNone;
|
sl@0
|
506 |
}
|
sl@0
|
507 |
|
sl@0
|
508 |
LOCAL_C TInt SIntRemoveTest()
|
sl@0
|
509 |
{
|
sl@0
|
510 |
TInt m=32;
|
sl@0
|
511 |
TInt n=m*m+1;
|
sl@0
|
512 |
RArray<SInt> a;
|
sl@0
|
513 |
TInt i;
|
sl@0
|
514 |
for (i=0; i<n; i++)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
a.Append(i);
|
sl@0
|
517 |
}
|
sl@0
|
518 |
TInt p=2;
|
sl@0
|
519 |
for (i=2; i<=m; i++)
|
sl@0
|
520 |
{
|
sl@0
|
521 |
TInt j;
|
sl@0
|
522 |
for (j=0; j<(2*i-2); j++)
|
sl@0
|
523 |
{
|
sl@0
|
524 |
a.Remove(p);
|
sl@0
|
525 |
}
|
sl@0
|
526 |
p++;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
if (a.Count()!=m+1)
|
sl@0
|
529 |
{
|
sl@0
|
530 |
a.Close();
|
sl@0
|
531 |
return -1;
|
sl@0
|
532 |
}
|
sl@0
|
533 |
for (i=0; i<m; i++)
|
sl@0
|
534 |
{
|
sl@0
|
535 |
if (a[i]!=i*i)
|
sl@0
|
536 |
{
|
sl@0
|
537 |
a.Close();
|
sl@0
|
538 |
return -2;
|
sl@0
|
539 |
}
|
sl@0
|
540 |
}
|
sl@0
|
541 |
a.Close();
|
sl@0
|
542 |
return KErrNone;
|
sl@0
|
543 |
}
|
sl@0
|
544 |
|
sl@0
|
545 |
LOCAL_C TInt SIntFindTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
546 |
{
|
sl@0
|
547 |
TInt n;
|
sl@0
|
548 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
549 |
{
|
sl@0
|
550 |
RArray<SInt> a;
|
sl@0
|
551 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
552 |
if (!pA)
|
sl@0
|
553 |
{
|
sl@0
|
554 |
a.Close();
|
sl@0
|
555 |
return -65535;
|
sl@0
|
556 |
}
|
sl@0
|
557 |
TInt i;
|
sl@0
|
558 |
for (i=0; i<aCount; i++)
|
sl@0
|
559 |
{
|
sl@0
|
560 |
TInt x=Random()&aRange;
|
sl@0
|
561 |
a.Append(x);
|
sl@0
|
562 |
pA[i]=x;
|
sl@0
|
563 |
}
|
sl@0
|
564 |
if (a.Count()!=aCount)
|
sl@0
|
565 |
{
|
sl@0
|
566 |
a.Close();
|
sl@0
|
567 |
return -1;
|
sl@0
|
568 |
}
|
sl@0
|
569 |
for (i=0; i<aCount; i++)
|
sl@0
|
570 |
{
|
sl@0
|
571 |
TInt r=a.Find(pA[i]);
|
sl@0
|
572 |
if (r<0 || pA[r]!=pA[i] || r>i)
|
sl@0
|
573 |
{
|
sl@0
|
574 |
a.Close();
|
sl@0
|
575 |
return -2;
|
sl@0
|
576 |
}
|
sl@0
|
577 |
TInt x=Random()&aRange;
|
sl@0
|
578 |
r=a.Find(x);
|
sl@0
|
579 |
if (r<0)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
TInt j;
|
sl@0
|
582 |
for (j=0; j<aCount; j++)
|
sl@0
|
583 |
{
|
sl@0
|
584 |
if (pA[j]==x)
|
sl@0
|
585 |
{
|
sl@0
|
586 |
a.Close();
|
sl@0
|
587 |
return -3;
|
sl@0
|
588 |
}
|
sl@0
|
589 |
}
|
sl@0
|
590 |
}
|
sl@0
|
591 |
else if (pA[r]!=x)
|
sl@0
|
592 |
{
|
sl@0
|
593 |
a.Close();
|
sl@0
|
594 |
return -4;
|
sl@0
|
595 |
}
|
sl@0
|
596 |
else
|
sl@0
|
597 |
{
|
sl@0
|
598 |
TInt j;
|
sl@0
|
599 |
for (j=0; j<r; j++)
|
sl@0
|
600 |
{
|
sl@0
|
601 |
if (pA[j]==x)
|
sl@0
|
602 |
{
|
sl@0
|
603 |
a.Close();
|
sl@0
|
604 |
return -5;
|
sl@0
|
605 |
}
|
sl@0
|
606 |
}
|
sl@0
|
607 |
}
|
sl@0
|
608 |
}
|
sl@0
|
609 |
delete pA;
|
sl@0
|
610 |
a.Close();
|
sl@0
|
611 |
}
|
sl@0
|
612 |
return KErrNone;
|
sl@0
|
613 |
}
|
sl@0
|
614 |
|
sl@0
|
615 |
LOCAL_C TInt SIntFindInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
616 |
// require aRange*aCount<2^32
|
sl@0
|
617 |
{
|
sl@0
|
618 |
TInt n;
|
sl@0
|
619 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
620 |
{
|
sl@0
|
621 |
RArray<SInt> a;
|
sl@0
|
622 |
TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
|
sl@0
|
623 |
if (!pA)
|
sl@0
|
624 |
{
|
sl@0
|
625 |
a.Close();
|
sl@0
|
626 |
return -65535;
|
sl@0
|
627 |
}
|
sl@0
|
628 |
TInt i=0;
|
sl@0
|
629 |
TInt y=-256;
|
sl@0
|
630 |
for(i=0; i<aCount; i++)
|
sl@0
|
631 |
{
|
sl@0
|
632 |
TInt x=Random()&aRange; // this is always >=0
|
sl@0
|
633 |
a.Append(y);
|
sl@0
|
634 |
pA[i]=y;
|
sl@0
|
635 |
y+=x;
|
sl@0
|
636 |
}
|
sl@0
|
637 |
if (a.Count()!=aCount)
|
sl@0
|
638 |
{
|
sl@0
|
639 |
a.Close();
|
sl@0
|
640 |
return -1;
|
sl@0
|
641 |
}
|
sl@0
|
642 |
for (i=0; i<aCount; i++)
|
sl@0
|
643 |
{
|
sl@0
|
644 |
TInt r=a.FindInSignedKeyOrder(pA[i]);
|
sl@0
|
645 |
if (r<0 || pA[r]!=pA[i])
|
sl@0
|
646 |
{
|
sl@0
|
647 |
a.Close();
|
sl@0
|
648 |
return -2;
|
sl@0
|
649 |
}
|
sl@0
|
650 |
TInt x=Random()&aRange;
|
sl@0
|
651 |
r=a.FindInSignedKeyOrder(x);
|
sl@0
|
652 |
if (r<0)
|
sl@0
|
653 |
{
|
sl@0
|
654 |
TInt j;
|
sl@0
|
655 |
for (j=0; j<aCount; j++)
|
sl@0
|
656 |
{
|
sl@0
|
657 |
if (pA[j]==x)
|
sl@0
|
658 |
{
|
sl@0
|
659 |
a.Close();
|
sl@0
|
660 |
return -3;
|
sl@0
|
661 |
}
|
sl@0
|
662 |
}
|
sl@0
|
663 |
}
|
sl@0
|
664 |
else if (pA[r]!=x)
|
sl@0
|
665 |
{
|
sl@0
|
666 |
a.Close();
|
sl@0
|
667 |
return -4;
|
sl@0
|
668 |
}
|
sl@0
|
669 |
}
|
sl@0
|
670 |
delete pA;
|
sl@0
|
671 |
a.Close();
|
sl@0
|
672 |
}
|
sl@0
|
673 |
return KErrNone;
|
sl@0
|
674 |
}
|
sl@0
|
675 |
|
sl@0
|
676 |
LOCAL_C TInt SIntFindInOrderTest2()
|
sl@0
|
677 |
{
|
sl@0
|
678 |
TInt i;
|
sl@0
|
679 |
RArray<SInt> sq;
|
sl@0
|
680 |
for (i=0; i<1024; i++)
|
sl@0
|
681 |
{
|
sl@0
|
682 |
TInt j=i*i;
|
sl@0
|
683 |
sq.Append(j);
|
sl@0
|
684 |
}
|
sl@0
|
685 |
for (i=0; i<10000; i++)
|
sl@0
|
686 |
{
|
sl@0
|
687 |
TInt x=Random()&1023;
|
sl@0
|
688 |
TInt y=x*x;
|
sl@0
|
689 |
TInt r=sq.FindInSignedKeyOrder(y);
|
sl@0
|
690 |
if (r!=x)
|
sl@0
|
691 |
{
|
sl@0
|
692 |
sq.Close();
|
sl@0
|
693 |
return -1;
|
sl@0
|
694 |
}
|
sl@0
|
695 |
}
|
sl@0
|
696 |
sq.Close();
|
sl@0
|
697 |
return 0;
|
sl@0
|
698 |
}
|
sl@0
|
699 |
|
sl@0
|
700 |
LOCAL_C TInt SIntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
701 |
{
|
sl@0
|
702 |
TInt n;
|
sl@0
|
703 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
704 |
{
|
sl@0
|
705 |
RArray<SInt> a;
|
sl@0
|
706 |
RArray<SInt> b;
|
sl@0
|
707 |
RArray<SInt> c;
|
sl@0
|
708 |
TInt i;
|
sl@0
|
709 |
TInt cc=0;
|
sl@0
|
710 |
for (i=0; i<aCount; i++)
|
sl@0
|
711 |
{
|
sl@0
|
712 |
TInt x=Random()&aRange;
|
sl@0
|
713 |
a.Append(x);
|
sl@0
|
714 |
b.InsertInSignedKeyOrderAllowRepeats(x);
|
sl@0
|
715 |
TInt r=c.InsertInSignedKeyOrder(x);
|
sl@0
|
716 |
if (r==KErrNone)
|
sl@0
|
717 |
cc++;
|
sl@0
|
718 |
}
|
sl@0
|
719 |
if (a.Count()!=aCount)
|
sl@0
|
720 |
{
|
sl@0
|
721 |
a.Close();
|
sl@0
|
722 |
b.Close();
|
sl@0
|
723 |
c.Close();
|
sl@0
|
724 |
return -1;
|
sl@0
|
725 |
}
|
sl@0
|
726 |
if (b.Count()!=aCount)
|
sl@0
|
727 |
{
|
sl@0
|
728 |
a.Close();
|
sl@0
|
729 |
b.Close();
|
sl@0
|
730 |
c.Close();
|
sl@0
|
731 |
return -2;
|
sl@0
|
732 |
}
|
sl@0
|
733 |
for (i=0; i<aCount-1; i++)
|
sl@0
|
734 |
{
|
sl@0
|
735 |
if (b[i]>b[i+1])
|
sl@0
|
736 |
{
|
sl@0
|
737 |
a.Close();
|
sl@0
|
738 |
b.Close();
|
sl@0
|
739 |
c.Close();
|
sl@0
|
740 |
return -3;
|
sl@0
|
741 |
}
|
sl@0
|
742 |
}
|
sl@0
|
743 |
for (i=0; i<aCount; i++)
|
sl@0
|
744 |
{
|
sl@0
|
745 |
if (a.Find(b[i])<0)
|
sl@0
|
746 |
{
|
sl@0
|
747 |
a.Close();
|
sl@0
|
748 |
b.Close();
|
sl@0
|
749 |
c.Close();
|
sl@0
|
750 |
return -4;
|
sl@0
|
751 |
}
|
sl@0
|
752 |
if (b.Find(a[i])<0)
|
sl@0
|
753 |
{
|
sl@0
|
754 |
a.Close();
|
sl@0
|
755 |
b.Close();
|
sl@0
|
756 |
c.Close();
|
sl@0
|
757 |
return -5;
|
sl@0
|
758 |
}
|
sl@0
|
759 |
if (c.Find(a[i])<0)
|
sl@0
|
760 |
{
|
sl@0
|
761 |
a.Close();
|
sl@0
|
762 |
b.Close();
|
sl@0
|
763 |
c.Close();
|
sl@0
|
764 |
return -6;
|
sl@0
|
765 |
}
|
sl@0
|
766 |
}
|
sl@0
|
767 |
if (c.Count()!=cc)
|
sl@0
|
768 |
{
|
sl@0
|
769 |
a.Close();
|
sl@0
|
770 |
b.Close();
|
sl@0
|
771 |
c.Close();
|
sl@0
|
772 |
return -7;
|
sl@0
|
773 |
}
|
sl@0
|
774 |
for (i=0; i<c.Count()-1; i++)
|
sl@0
|
775 |
{
|
sl@0
|
776 |
if (c[i]>=c[i+1])
|
sl@0
|
777 |
{
|
sl@0
|
778 |
a.Close();
|
sl@0
|
779 |
b.Close();
|
sl@0
|
780 |
c.Close();
|
sl@0
|
781 |
return -8;
|
sl@0
|
782 |
}
|
sl@0
|
783 |
if (a.Find(c[i])<0)
|
sl@0
|
784 |
{
|
sl@0
|
785 |
a.Close();
|
sl@0
|
786 |
b.Close();
|
sl@0
|
787 |
c.Close();
|
sl@0
|
788 |
return -9;
|
sl@0
|
789 |
}
|
sl@0
|
790 |
}
|
sl@0
|
791 |
a.Close();
|
sl@0
|
792 |
b.Close();
|
sl@0
|
793 |
c.Close();
|
sl@0
|
794 |
}
|
sl@0
|
795 |
return KErrNone;
|
sl@0
|
796 |
}
|
sl@0
|
797 |
|
sl@0
|
798 |
LOCAL_C TInt SIntInsertInOrderTest2()
|
sl@0
|
799 |
{
|
sl@0
|
800 |
TInt i;
|
sl@0
|
801 |
RArray<SInt> sq;
|
sl@0
|
802 |
for (i=0; i<1024; i++)
|
sl@0
|
803 |
{
|
sl@0
|
804 |
TInt j=i*i;
|
sl@0
|
805 |
sq.InsertInSignedKeyOrder(j);
|
sl@0
|
806 |
sq.InsertInSignedKeyOrder(-j);
|
sl@0
|
807 |
}
|
sl@0
|
808 |
if (sq.Count()!=2047)
|
sl@0
|
809 |
{
|
sl@0
|
810 |
sq.Close();
|
sl@0
|
811 |
return -1;
|
sl@0
|
812 |
}
|
sl@0
|
813 |
for (i=0; i<2047; i++)
|
sl@0
|
814 |
{
|
sl@0
|
815 |
TInt y=0;
|
sl@0
|
816 |
if (i<1023)
|
sl@0
|
817 |
y=-(1023-i)*(1023-i);
|
sl@0
|
818 |
else if (i==1023)
|
sl@0
|
819 |
y=0;
|
sl@0
|
820 |
else if (i>1023)
|
sl@0
|
821 |
y=(i-1023)*(i-1023);
|
sl@0
|
822 |
if (sq[i]!=y)
|
sl@0
|
823 |
{
|
sl@0
|
824 |
sq.Close();
|
sl@0
|
825 |
return -2;
|
sl@0
|
826 |
}
|
sl@0
|
827 |
}
|
sl@0
|
828 |
sq.Close();
|
sl@0
|
829 |
return 0;
|
sl@0
|
830 |
}
|
sl@0
|
831 |
|
sl@0
|
832 |
LOCAL_C TInt SIntSortTest(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
833 |
{
|
sl@0
|
834 |
TInt n;
|
sl@0
|
835 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
836 |
{
|
sl@0
|
837 |
RArray<SInt> a;
|
sl@0
|
838 |
RArray<SInt> b;
|
sl@0
|
839 |
TInt i;
|
sl@0
|
840 |
for (i=0; i<aCount; i++)
|
sl@0
|
841 |
{
|
sl@0
|
842 |
TInt x=Random()&aRange;
|
sl@0
|
843 |
a.Append(x);
|
sl@0
|
844 |
b.InsertInSignedKeyOrderAllowRepeats(x);
|
sl@0
|
845 |
}
|
sl@0
|
846 |
a.SortSigned();
|
sl@0
|
847 |
if (a.Count()!=aCount)
|
sl@0
|
848 |
{
|
sl@0
|
849 |
a.Close();
|
sl@0
|
850 |
b.Close();
|
sl@0
|
851 |
return -1;
|
sl@0
|
852 |
}
|
sl@0
|
853 |
if (b.Count()!=aCount)
|
sl@0
|
854 |
{
|
sl@0
|
855 |
a.Close();
|
sl@0
|
856 |
b.Close();
|
sl@0
|
857 |
return -2;
|
sl@0
|
858 |
}
|
sl@0
|
859 |
for (i=0; i<aCount; i++)
|
sl@0
|
860 |
{
|
sl@0
|
861 |
if (a[i]!=b[i])
|
sl@0
|
862 |
{
|
sl@0
|
863 |
a.Close();
|
sl@0
|
864 |
b.Close();
|
sl@0
|
865 |
return -3;
|
sl@0
|
866 |
}
|
sl@0
|
867 |
}
|
sl@0
|
868 |
a.Close();
|
sl@0
|
869 |
b.Close();
|
sl@0
|
870 |
}
|
sl@0
|
871 |
return KErrNone;
|
sl@0
|
872 |
}
|
sl@0
|
873 |
|
sl@0
|
874 |
TInt IntSpecificFindTests1()
|
sl@0
|
875 |
{
|
sl@0
|
876 |
RArray<TInt> a;
|
sl@0
|
877 |
TInt i;
|
sl@0
|
878 |
TInt v = 0;
|
sl@0
|
879 |
TInt first, last, any;
|
sl@0
|
880 |
for (i=0; i<101; ++i)
|
sl@0
|
881 |
{
|
sl@0
|
882 |
if (v*v<i)
|
sl@0
|
883 |
++v;
|
sl@0
|
884 |
TInt r = a.InsertInOrderAllowRepeats(v);
|
sl@0
|
885 |
test(r==KErrNone);
|
sl@0
|
886 |
}
|
sl@0
|
887 |
test (a.Count()==101);
|
sl@0
|
888 |
for (v=0; v<=10; ++v)
|
sl@0
|
889 |
{
|
sl@0
|
890 |
first = a.SpecificFindInOrder(v, EArrayFindMode_First);
|
sl@0
|
891 |
last = a.SpecificFindInOrder(v, EArrayFindMode_Last);
|
sl@0
|
892 |
any = a.SpecificFindInOrder(v, EArrayFindMode_Any);
|
sl@0
|
893 |
test(first>=0 && first<a.Count());
|
sl@0
|
894 |
test(last>=0 && last<=a.Count());
|
sl@0
|
895 |
test(any>=first && any<last);
|
sl@0
|
896 |
if (v==0)
|
sl@0
|
897 |
{
|
sl@0
|
898 |
test(first==0 && last==1);
|
sl@0
|
899 |
}
|
sl@0
|
900 |
else if (v==1)
|
sl@0
|
901 |
{
|
sl@0
|
902 |
test(first==1 && last==2);
|
sl@0
|
903 |
}
|
sl@0
|
904 |
else
|
sl@0
|
905 |
{
|
sl@0
|
906 |
TInt expf = (v-1)*(v-1)+1;
|
sl@0
|
907 |
TInt expl = v*v+1;
|
sl@0
|
908 |
test(expf==first && expl==last);
|
sl@0
|
909 |
}
|
sl@0
|
910 |
TInt n = last - first;
|
sl@0
|
911 |
TInt expected = v ? 2*v-1 : 1;
|
sl@0
|
912 |
test(n == expected);
|
sl@0
|
913 |
}
|
sl@0
|
914 |
first = a.SpecificFindInOrder(11, EArrayFindMode_First);
|
sl@0
|
915 |
test(first == KErrNotFound);
|
sl@0
|
916 |
last = a.SpecificFindInOrder(11, EArrayFindMode_Last);
|
sl@0
|
917 |
test(last == KErrNotFound);
|
sl@0
|
918 |
any = a.SpecificFindInOrder(11, EArrayFindMode_Any);
|
sl@0
|
919 |
test(any == KErrNotFound);
|
sl@0
|
920 |
a.Close();
|
sl@0
|
921 |
return KErrNone;
|
sl@0
|
922 |
}
|
sl@0
|
923 |
|
sl@0
|
924 |
TInt IntSpecificFindTests2(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
925 |
{
|
sl@0
|
926 |
TInt n;
|
sl@0
|
927 |
TInt nmiss = 0;
|
sl@0
|
928 |
TInt nrpt = 0;
|
sl@0
|
929 |
TInt ntot = 0;
|
sl@0
|
930 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
931 |
{
|
sl@0
|
932 |
RArray<TInt> a;
|
sl@0
|
933 |
RArray<TInt> b;
|
sl@0
|
934 |
TInt i;
|
sl@0
|
935 |
for (i=0; i<aCount; i++)
|
sl@0
|
936 |
{
|
sl@0
|
937 |
TInt x=Random()&aRange;
|
sl@0
|
938 |
x-=(aRange>>1);
|
sl@0
|
939 |
a.Append(x);
|
sl@0
|
940 |
b.InsertInOrderAllowRepeats(x);
|
sl@0
|
941 |
}
|
sl@0
|
942 |
a.Sort();
|
sl@0
|
943 |
test(a.Count()==aCount);
|
sl@0
|
944 |
test(b.Count()==aCount);
|
sl@0
|
945 |
for (i=0; i<aCount; i++)
|
sl@0
|
946 |
test(a[i]==b[i]);
|
sl@0
|
947 |
for (i=-(aRange>>1); i<=(aRange>>1); ++i)
|
sl@0
|
948 |
{
|
sl@0
|
949 |
TInt first = a.SpecificFindInOrder(i, EArrayFindMode_First);
|
sl@0
|
950 |
TInt last = a.SpecificFindInOrder(i, EArrayFindMode_Last);
|
sl@0
|
951 |
TInt any = a.SpecificFindInOrder(i, EArrayFindMode_Any);
|
sl@0
|
952 |
TInt fi, li, ai;
|
sl@0
|
953 |
TInt first2 = a.SpecificFindInOrder(i, fi, EArrayFindMode_First);
|
sl@0
|
954 |
TInt last2 = a.SpecificFindInOrder(i, li, EArrayFindMode_Last);
|
sl@0
|
955 |
TInt any2 = a.SpecificFindInOrder(i, ai, EArrayFindMode_Any);
|
sl@0
|
956 |
++ntot;
|
sl@0
|
957 |
if (first < 0)
|
sl@0
|
958 |
{
|
sl@0
|
959 |
test(first == KErrNotFound);
|
sl@0
|
960 |
test(first == last);
|
sl@0
|
961 |
test(first == any);
|
sl@0
|
962 |
test(first == first2);
|
sl@0
|
963 |
test(first == last2);
|
sl@0
|
964 |
test(first == any2);
|
sl@0
|
965 |
test(fi == li);
|
sl@0
|
966 |
test(fi == ai);
|
sl@0
|
967 |
test(li==aCount || a[li]>i);
|
sl@0
|
968 |
test(li==0 || a[li-1]<i);
|
sl@0
|
969 |
++nmiss;
|
sl@0
|
970 |
}
|
sl@0
|
971 |
else
|
sl@0
|
972 |
{
|
sl@0
|
973 |
test(first2 == KErrNone);
|
sl@0
|
974 |
test(last2 == KErrNone);
|
sl@0
|
975 |
test(any2 == KErrNone);
|
sl@0
|
976 |
test(first == fi);
|
sl@0
|
977 |
test(last == li);
|
sl@0
|
978 |
test(any == ai);
|
sl@0
|
979 |
test(a[fi] == i);
|
sl@0
|
980 |
test(a[li-1] == i);
|
sl@0
|
981 |
test(li==aCount || a[li]>i);
|
sl@0
|
982 |
test(ai>=fi && ai<li);
|
sl@0
|
983 |
test(a[ai] == i);
|
sl@0
|
984 |
if (li-fi > 1)
|
sl@0
|
985 |
++nrpt;
|
sl@0
|
986 |
}
|
sl@0
|
987 |
}
|
sl@0
|
988 |
a.Close();
|
sl@0
|
989 |
b.Close();
|
sl@0
|
990 |
}
|
sl@0
|
991 |
test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
|
sl@0
|
992 |
return KErrNone;
|
sl@0
|
993 |
}
|
sl@0
|
994 |
|
sl@0
|
995 |
TInt SIntSpecificFindTests2(TInt aCount, TInt aNumTests, TInt aRange)
|
sl@0
|
996 |
{
|
sl@0
|
997 |
TInt n;
|
sl@0
|
998 |
TInt nmiss = 0;
|
sl@0
|
999 |
TInt nrpt = 0;
|
sl@0
|
1000 |
TInt ntot = 0;
|
sl@0
|
1001 |
for (n=0; n<aNumTests; n++)
|
sl@0
|
1002 |
{
|
sl@0
|
1003 |
RArray<SInt> a;
|
sl@0
|
1004 |
RArray<SInt> b;
|
sl@0
|
1005 |
TInt i;
|
sl@0
|
1006 |
for (i=0; i<aCount; i++)
|
sl@0
|
1007 |
{
|
sl@0
|
1008 |
TInt x=Random()&aRange;
|
sl@0
|
1009 |
x-=(aRange>>1);
|
sl@0
|
1010 |
a.Append(x);
|
sl@0
|
1011 |
b.InsertInSignedKeyOrderAllowRepeats(x);
|
sl@0
|
1012 |
}
|
sl@0
|
1013 |
a.SortSigned();
|
sl@0
|
1014 |
test(a.Count()==aCount);
|
sl@0
|
1015 |
test(b.Count()==aCount);
|
sl@0
|
1016 |
for (i=0; i<aCount; i++)
|
sl@0
|
1017 |
test(a[i]==b[i]);
|
sl@0
|
1018 |
for (i=-(aRange>>1); i<=(aRange>>1); ++i)
|
sl@0
|
1019 |
{
|
sl@0
|
1020 |
TInt first = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_First);
|
sl@0
|
1021 |
TInt last = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_Last);
|
sl@0
|
1022 |
TInt any = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_Any);
|
sl@0
|
1023 |
TInt fi, li, ai;
|
sl@0
|
1024 |
TInt first2 = a.SpecificFindInSignedKeyOrder(i, fi, EArrayFindMode_First);
|
sl@0
|
1025 |
TInt last2 = a.SpecificFindInSignedKeyOrder(i, li, EArrayFindMode_Last);
|
sl@0
|
1026 |
TInt any2 = a.SpecificFindInSignedKeyOrder(i, ai, EArrayFindMode_Any);
|
sl@0
|
1027 |
++ntot;
|
sl@0
|
1028 |
if (first < 0)
|
sl@0
|
1029 |
{
|
sl@0
|
1030 |
test(first == KErrNotFound);
|
sl@0
|
1031 |
test(first == last);
|
sl@0
|
1032 |
test(first == any);
|
sl@0
|
1033 |
test(first == first2);
|
sl@0
|
1034 |
test(first == last2);
|
sl@0
|
1035 |
test(first == any2);
|
sl@0
|
1036 |
test(fi == li);
|
sl@0
|
1037 |
test(fi == ai);
|
sl@0
|
1038 |
test(li==aCount || a[li]>i);
|
sl@0
|
1039 |
test(li==0 || a[li-1]<i);
|
sl@0
|
1040 |
++nmiss;
|
sl@0
|
1041 |
}
|
sl@0
|
1042 |
else
|
sl@0
|
1043 |
{
|
sl@0
|
1044 |
test(first2 == KErrNone);
|
sl@0
|
1045 |
test(last2 == KErrNone);
|
sl@0
|
1046 |
test(any2 == KErrNone);
|
sl@0
|
1047 |
test(first == fi);
|
sl@0
|
1048 |
test(last == li);
|
sl@0
|
1049 |
test(any == ai);
|
sl@0
|
1050 |
test(a[fi] == i);
|
sl@0
|
1051 |
test(a[li-1] == i);
|
sl@0
|
1052 |
test(li==aCount || a[li]>i);
|
sl@0
|
1053 |
test(ai>=fi && ai<li);
|
sl@0
|
1054 |
test(a[ai] == i);
|
sl@0
|
1055 |
if (li-fi > 1)
|
sl@0
|
1056 |
++nrpt;
|
sl@0
|
1057 |
}
|
sl@0
|
1058 |
}
|
sl@0
|
1059 |
a.Close();
|
sl@0
|
1060 |
b.Close();
|
sl@0
|
1061 |
}
|
sl@0
|
1062 |
test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
|
sl@0
|
1063 |
return KErrNone;
|
sl@0
|
1064 |
}
|
sl@0
|
1065 |
|
sl@0
|
1066 |
GLDEF_C void DoIntArrayTests()
|
sl@0
|
1067 |
{
|
sl@0
|
1068 |
test.Start(_L("Signed Integer Arrays..."));
|
sl@0
|
1069 |
|
sl@0
|
1070 |
test.Next(_L("AppendAndAccess tests..."));
|
sl@0
|
1071 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1072 |
test(IntAppendAndAccessTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1073 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1074 |
test(IntAppendAndAccessTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1075 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1076 |
test(IntAppendAndAccessTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1077 |
|
sl@0
|
1078 |
test.Next(_L("Remove tests..."));
|
sl@0
|
1079 |
test(IntRemoveTest()==KErrNone);
|
sl@0
|
1080 |
|
sl@0
|
1081 |
test.Next(_L("Find tests..."));
|
sl@0
|
1082 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1083 |
test(IntFindTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1084 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1085 |
test(IntFindTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1086 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1087 |
test(IntFindTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1088 |
|
sl@0
|
1089 |
test.Next(_L("FindInOrder tests..."));
|
sl@0
|
1090 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1091 |
test(IntFindInOrderTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1092 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1093 |
test(IntFindInOrderTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1094 |
test.Next(_L("Count 100 Range 4095"));
|
sl@0
|
1095 |
test(IntFindInOrderTest(100,NUM_TESTS,4095)==KErrNone);
|
sl@0
|
1096 |
test.Next(_L("Squares"));
|
sl@0
|
1097 |
test(IntFindInOrderTest2()==KErrNone);
|
sl@0
|
1098 |
|
sl@0
|
1099 |
test.Next(_L("InsertInOrder tests..."));
|
sl@0
|
1100 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1101 |
test(IntInsertInOrderTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1102 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1103 |
test(IntInsertInOrderTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1104 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1105 |
test(IntInsertInOrderTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1106 |
test.Next(_L("Squares"));
|
sl@0
|
1107 |
test(IntInsertInOrderTest2()==KErrNone);
|
sl@0
|
1108 |
|
sl@0
|
1109 |
test.Next(_L("Sort tests..."));
|
sl@0
|
1110 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1111 |
test(IntSortTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1112 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1113 |
test(IntSortTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1114 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1115 |
test(IntSortTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1116 |
|
sl@0
|
1117 |
test.End();
|
sl@0
|
1118 |
|
sl@0
|
1119 |
test.Start(_L("4 byte RArrays..."));
|
sl@0
|
1120 |
|
sl@0
|
1121 |
test.Next(_L("AppendAndAccess tests..."));
|
sl@0
|
1122 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1123 |
test(SIntAppendAndAccessTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1124 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1125 |
test(SIntAppendAndAccessTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1126 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1127 |
test(SIntAppendAndAccessTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1128 |
|
sl@0
|
1129 |
test.Next(_L("Remove tests..."));
|
sl@0
|
1130 |
test(SIntRemoveTest()==KErrNone);
|
sl@0
|
1131 |
|
sl@0
|
1132 |
test.Next(_L("Find tests..."));
|
sl@0
|
1133 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1134 |
test(SIntFindTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1135 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1136 |
test(SIntFindTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1137 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1138 |
test(SIntFindTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1139 |
|
sl@0
|
1140 |
test.Next(_L("FindInOrder tests..."));
|
sl@0
|
1141 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1142 |
test(SIntFindInOrderTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1143 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1144 |
test(SIntFindInOrderTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1145 |
test.Next(_L("Count 100 Range 4095"));
|
sl@0
|
1146 |
test(SIntFindInOrderTest(100,NUM_TESTS,4095)==KErrNone);
|
sl@0
|
1147 |
test.Next(_L("Squares"));
|
sl@0
|
1148 |
test(SIntFindInOrderTest2()==KErrNone);
|
sl@0
|
1149 |
|
sl@0
|
1150 |
test.Next(_L("InsertInOrder tests..."));
|
sl@0
|
1151 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1152 |
test(SIntInsertInOrderTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1153 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1154 |
test(SIntInsertInOrderTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1155 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1156 |
test(SIntInsertInOrderTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1157 |
test.Next(_L("Squares"));
|
sl@0
|
1158 |
test(SIntInsertInOrderTest2()==KErrNone);
|
sl@0
|
1159 |
|
sl@0
|
1160 |
test.Next(_L("Sort tests..."));
|
sl@0
|
1161 |
test.Next(_L("Count 10 Range 15"));
|
sl@0
|
1162 |
test(SIntSortTest(10,NUM_TESTS,15)==KErrNone);
|
sl@0
|
1163 |
test.Next(_L("Count 20 Range 255"));
|
sl@0
|
1164 |
test(SIntSortTest(20,NUM_TESTS,255)==KErrNone);
|
sl@0
|
1165 |
test.Next(_L("Count 100 Range all"));
|
sl@0
|
1166 |
test(SIntSortTest(100,NUM_TESTS,-1)==KErrNone);
|
sl@0
|
1167 |
|
sl@0
|
1168 |
test.Next(_L("IntSpecificFindTests..."));
|
sl@0
|
1169 |
test(IntSpecificFindTests1()==KErrNone);
|
sl@0
|
1170 |
test(IntSpecificFindTests2(100, 10, 15)==KErrNone);
|
sl@0
|
1171 |
test(IntSpecificFindTests2(100, 10, 127)==KErrNone);
|
sl@0
|
1172 |
|
sl@0
|
1173 |
test.Next(_L("SIntSpecificFindTests..."));
|
sl@0
|
1174 |
test(SIntSpecificFindTests2(100, 10, 15)==KErrNone);
|
sl@0
|
1175 |
test(SIntSpecificFindTests2(100, 10, 127)==KErrNone);
|
sl@0
|
1176 |
test.End();
|
sl@0
|
1177 |
}
|