Update contrib.
1 // Copyright (c) 1994-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 the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\buffer\int_arr.cpp
24 GLREF_C TInt Random();
29 operator TInt() {return i;}
34 LOCAL_C TInt IntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt aRange)
37 for (n=0; n<aNumTests; n++)
40 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
47 for (i=0; i<aCount; i++)
49 TInt x=Random()&aRange;
53 if (a.Count()!=aCount)
58 for (i=0; i<aCount; i++)
65 TInt x=Random()&aRange;
69 if (a.Count()!=aCount)
74 for (i=0; i<aCount; i++)
88 LOCAL_C TInt IntRemoveTest()
102 for (j=0; j<(2*i-2); j++)
125 LOCAL_C TInt IntFindTest(TInt aCount, TInt aNumTests, TInt aRange)
128 for (n=0; n<aNumTests; n++)
131 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
138 for (i=0; i<aCount; i++)
140 TInt x=Random()&aRange;
144 if (a.Count()!=aCount)
149 for (i=0; i<aCount; i++)
151 TInt r=a.Find(pA[i]);
152 if (r<0 || pA[r]!=pA[i] || r>i)
157 TInt x=Random()&aRange;
162 for (j=0; j<aCount; j++)
195 LOCAL_C TInt IntFindInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
196 // require aRange*aCount<2^32
199 for (n=0; n<aNumTests; n++)
202 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
210 for(i=0; i<aCount; i++)
212 TInt x=Random()&aRange; // this is always >=0
217 if (a.Count()!=aCount)
222 for (i=0; i<aCount; i++)
224 TInt r=a.FindInOrder(pA[i]);
225 if (r<0 || pA[r]!=pA[i])
230 TInt x=Random()&aRange;
235 for (j=0; j<aCount; j++)
256 LOCAL_C TInt IntFindInOrderTest2()
260 for (i=0; i<1024; i++)
265 for (i=0; i<10000; i++)
267 TInt x=Random()&1023;
269 TInt r=sq.FindInOrder(y);
280 LOCAL_C TInt IntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
283 for (n=0; n<aNumTests; n++)
290 for (i=0; i<aCount; i++)
292 TInt x=Random()&aRange;
294 b.InsertInOrderAllowRepeats(x);
295 TInt r=c.InsertInOrder(x);
299 if (a.Count()!=aCount)
306 if (b.Count()!=aCount)
313 for (i=0; i<aCount-1; i++)
323 for (i=0; i<aCount; i++)
354 for (i=0; i<c.Count()-1; i++)
378 LOCAL_C TInt IntInsertInOrderTest2()
382 for (i=0; i<1024; i++)
386 sq.InsertInOrder(-j);
388 if (sq.Count()!=2047)
393 for (i=0; i<2047; i++)
397 y=-(1023-i)*(1023-i);
412 LOCAL_C TInt IntSortTest(TInt aCount, TInt aNumTests, TInt aRange)
415 for (n=0; n<aNumTests; n++)
420 for (i=0; i<aCount; i++)
422 TInt x=Random()&aRange;
424 b.InsertInOrderAllowRepeats(x);
427 if (a.Count()!=aCount)
433 if (b.Count()!=aCount)
439 for (i=0; i<aCount; i++)
454 LOCAL_C TInt SIntAppendAndAccessTest(TInt aCount, TInt aNumTests, TInt aRange)
457 for (n=0; n<aNumTests; n++)
460 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
467 for (i=0; i<aCount; i++)
469 TInt x=Random()&aRange;
473 if (a.Count()!=aCount)
478 for (i=0; i<aCount; i++)
485 TInt x=Random()&aRange;
489 if (a.Count()!=aCount)
494 for (i=0; i<aCount; i++)
508 LOCAL_C TInt SIntRemoveTest()
522 for (j=0; j<(2*i-2); j++)
545 LOCAL_C TInt SIntFindTest(TInt aCount, TInt aNumTests, TInt aRange)
548 for (n=0; n<aNumTests; n++)
551 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
558 for (i=0; i<aCount; i++)
560 TInt x=Random()&aRange;
564 if (a.Count()!=aCount)
569 for (i=0; i<aCount; i++)
571 TInt r=a.Find(pA[i]);
572 if (r<0 || pA[r]!=pA[i] || r>i)
577 TInt x=Random()&aRange;
582 for (j=0; j<aCount; j++)
615 LOCAL_C TInt SIntFindInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
616 // require aRange*aCount<2^32
619 for (n=0; n<aNumTests; n++)
622 TInt *pA=(TInt*)User::Alloc(aCount*sizeof(TInt));
630 for(i=0; i<aCount; i++)
632 TInt x=Random()&aRange; // this is always >=0
637 if (a.Count()!=aCount)
642 for (i=0; i<aCount; i++)
644 TInt r=a.FindInSignedKeyOrder(pA[i]);
645 if (r<0 || pA[r]!=pA[i])
650 TInt x=Random()&aRange;
651 r=a.FindInSignedKeyOrder(x);
655 for (j=0; j<aCount; j++)
676 LOCAL_C TInt SIntFindInOrderTest2()
680 for (i=0; i<1024; i++)
685 for (i=0; i<10000; i++)
687 TInt x=Random()&1023;
689 TInt r=sq.FindInSignedKeyOrder(y);
700 LOCAL_C TInt SIntInsertInOrderTest(TInt aCount, TInt aNumTests, TInt aRange)
703 for (n=0; n<aNumTests; n++)
710 for (i=0; i<aCount; i++)
712 TInt x=Random()&aRange;
714 b.InsertInSignedKeyOrderAllowRepeats(x);
715 TInt r=c.InsertInSignedKeyOrder(x);
719 if (a.Count()!=aCount)
726 if (b.Count()!=aCount)
733 for (i=0; i<aCount-1; i++)
743 for (i=0; i<aCount; i++)
774 for (i=0; i<c.Count()-1; i++)
798 LOCAL_C TInt SIntInsertInOrderTest2()
802 for (i=0; i<1024; i++)
805 sq.InsertInSignedKeyOrder(j);
806 sq.InsertInSignedKeyOrder(-j);
808 if (sq.Count()!=2047)
813 for (i=0; i<2047; i++)
817 y=-(1023-i)*(1023-i);
832 LOCAL_C TInt SIntSortTest(TInt aCount, TInt aNumTests, TInt aRange)
835 for (n=0; n<aNumTests; n++)
840 for (i=0; i<aCount; i++)
842 TInt x=Random()&aRange;
844 b.InsertInSignedKeyOrderAllowRepeats(x);
847 if (a.Count()!=aCount)
853 if (b.Count()!=aCount)
859 for (i=0; i<aCount; i++)
874 TInt IntSpecificFindTests1()
879 TInt first, last, any;
880 for (i=0; i<101; ++i)
884 TInt r = a.InsertInOrderAllowRepeats(v);
887 test (a.Count()==101);
888 for (v=0; v<=10; ++v)
890 first = a.SpecificFindInOrder(v, EArrayFindMode_First);
891 last = a.SpecificFindInOrder(v, EArrayFindMode_Last);
892 any = a.SpecificFindInOrder(v, EArrayFindMode_Any);
893 test(first>=0 && first<a.Count());
894 test(last>=0 && last<=a.Count());
895 test(any>=first && any<last);
898 test(first==0 && last==1);
902 test(first==1 && last==2);
906 TInt expf = (v-1)*(v-1)+1;
908 test(expf==first && expl==last);
910 TInt n = last - first;
911 TInt expected = v ? 2*v-1 : 1;
914 first = a.SpecificFindInOrder(11, EArrayFindMode_First);
915 test(first == KErrNotFound);
916 last = a.SpecificFindInOrder(11, EArrayFindMode_Last);
917 test(last == KErrNotFound);
918 any = a.SpecificFindInOrder(11, EArrayFindMode_Any);
919 test(any == KErrNotFound);
924 TInt IntSpecificFindTests2(TInt aCount, TInt aNumTests, TInt aRange)
930 for (n=0; n<aNumTests; n++)
935 for (i=0; i<aCount; i++)
937 TInt x=Random()&aRange;
940 b.InsertInOrderAllowRepeats(x);
943 test(a.Count()==aCount);
944 test(b.Count()==aCount);
945 for (i=0; i<aCount; i++)
947 for (i=-(aRange>>1); i<=(aRange>>1); ++i)
949 TInt first = a.SpecificFindInOrder(i, EArrayFindMode_First);
950 TInt last = a.SpecificFindInOrder(i, EArrayFindMode_Last);
951 TInt any = a.SpecificFindInOrder(i, EArrayFindMode_Any);
953 TInt first2 = a.SpecificFindInOrder(i, fi, EArrayFindMode_First);
954 TInt last2 = a.SpecificFindInOrder(i, li, EArrayFindMode_Last);
955 TInt any2 = a.SpecificFindInOrder(i, ai, EArrayFindMode_Any);
959 test(first == KErrNotFound);
962 test(first == first2);
963 test(first == last2);
967 test(li==aCount || a[li]>i);
968 test(li==0 || a[li-1]<i);
973 test(first2 == KErrNone);
974 test(last2 == KErrNone);
975 test(any2 == KErrNone);
981 test(li==aCount || a[li]>i);
982 test(ai>=fi && ai<li);
991 test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
995 TInt SIntSpecificFindTests2(TInt aCount, TInt aNumTests, TInt aRange)
1001 for (n=0; n<aNumTests; n++)
1006 for (i=0; i<aCount; i++)
1008 TInt x=Random()&aRange;
1011 b.InsertInSignedKeyOrderAllowRepeats(x);
1014 test(a.Count()==aCount);
1015 test(b.Count()==aCount);
1016 for (i=0; i<aCount; i++)
1018 for (i=-(aRange>>1); i<=(aRange>>1); ++i)
1020 TInt first = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_First);
1021 TInt last = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_Last);
1022 TInt any = a.SpecificFindInSignedKeyOrder(i, EArrayFindMode_Any);
1024 TInt first2 = a.SpecificFindInSignedKeyOrder(i, fi, EArrayFindMode_First);
1025 TInt last2 = a.SpecificFindInSignedKeyOrder(i, li, EArrayFindMode_Last);
1026 TInt any2 = a.SpecificFindInSignedKeyOrder(i, ai, EArrayFindMode_Any);
1030 test(first == KErrNotFound);
1031 test(first == last);
1033 test(first == first2);
1034 test(first == last2);
1035 test(first == any2);
1038 test(li==aCount || a[li]>i);
1039 test(li==0 || a[li-1]<i);
1044 test(first2 == KErrNone);
1045 test(last2 == KErrNone);
1046 test(any2 == KErrNone);
1052 test(li==aCount || a[li]>i);
1053 test(ai>=fi && ai<li);
1062 test.Printf(_L("ntot=%d nmiss=%d nrpt=%d\n"), ntot, nmiss, nrpt);
1066 GLDEF_C void DoIntArrayTests()
1068 test.Start(_L("Signed Integer Arrays..."));
1070 test.Next(_L("AppendAndAccess tests..."));
1071 test.Next(_L("Count 10 Range 15"));
1072 test(IntAppendAndAccessTest(10,NUM_TESTS,15)==KErrNone);
1073 test.Next(_L("Count 20 Range 255"));
1074 test(IntAppendAndAccessTest(20,NUM_TESTS,255)==KErrNone);
1075 test.Next(_L("Count 100 Range all"));
1076 test(IntAppendAndAccessTest(100,NUM_TESTS,-1)==KErrNone);
1078 test.Next(_L("Remove tests..."));
1079 test(IntRemoveTest()==KErrNone);
1081 test.Next(_L("Find tests..."));
1082 test.Next(_L("Count 10 Range 15"));
1083 test(IntFindTest(10,NUM_TESTS,15)==KErrNone);
1084 test.Next(_L("Count 20 Range 255"));
1085 test(IntFindTest(20,NUM_TESTS,255)==KErrNone);
1086 test.Next(_L("Count 100 Range all"));
1087 test(IntFindTest(100,NUM_TESTS,-1)==KErrNone);
1089 test.Next(_L("FindInOrder tests..."));
1090 test.Next(_L("Count 10 Range 15"));
1091 test(IntFindInOrderTest(10,NUM_TESTS,15)==KErrNone);
1092 test.Next(_L("Count 20 Range 255"));
1093 test(IntFindInOrderTest(20,NUM_TESTS,255)==KErrNone);
1094 test.Next(_L("Count 100 Range 4095"));
1095 test(IntFindInOrderTest(100,NUM_TESTS,4095)==KErrNone);
1096 test.Next(_L("Squares"));
1097 test(IntFindInOrderTest2()==KErrNone);
1099 test.Next(_L("InsertInOrder tests..."));
1100 test.Next(_L("Count 10 Range 15"));
1101 test(IntInsertInOrderTest(10,NUM_TESTS,15)==KErrNone);
1102 test.Next(_L("Count 20 Range 255"));
1103 test(IntInsertInOrderTest(20,NUM_TESTS,255)==KErrNone);
1104 test.Next(_L("Count 100 Range all"));
1105 test(IntInsertInOrderTest(100,NUM_TESTS,-1)==KErrNone);
1106 test.Next(_L("Squares"));
1107 test(IntInsertInOrderTest2()==KErrNone);
1109 test.Next(_L("Sort tests..."));
1110 test.Next(_L("Count 10 Range 15"));
1111 test(IntSortTest(10,NUM_TESTS,15)==KErrNone);
1112 test.Next(_L("Count 20 Range 255"));
1113 test(IntSortTest(20,NUM_TESTS,255)==KErrNone);
1114 test.Next(_L("Count 100 Range all"));
1115 test(IntSortTest(100,NUM_TESTS,-1)==KErrNone);
1119 test.Start(_L("4 byte RArrays..."));
1121 test.Next(_L("AppendAndAccess tests..."));
1122 test.Next(_L("Count 10 Range 15"));
1123 test(SIntAppendAndAccessTest(10,NUM_TESTS,15)==KErrNone);
1124 test.Next(_L("Count 20 Range 255"));
1125 test(SIntAppendAndAccessTest(20,NUM_TESTS,255)==KErrNone);
1126 test.Next(_L("Count 100 Range all"));
1127 test(SIntAppendAndAccessTest(100,NUM_TESTS,-1)==KErrNone);
1129 test.Next(_L("Remove tests..."));
1130 test(SIntRemoveTest()==KErrNone);
1132 test.Next(_L("Find tests..."));
1133 test.Next(_L("Count 10 Range 15"));
1134 test(SIntFindTest(10,NUM_TESTS,15)==KErrNone);
1135 test.Next(_L("Count 20 Range 255"));
1136 test(SIntFindTest(20,NUM_TESTS,255)==KErrNone);
1137 test.Next(_L("Count 100 Range all"));
1138 test(SIntFindTest(100,NUM_TESTS,-1)==KErrNone);
1140 test.Next(_L("FindInOrder tests..."));
1141 test.Next(_L("Count 10 Range 15"));
1142 test(SIntFindInOrderTest(10,NUM_TESTS,15)==KErrNone);
1143 test.Next(_L("Count 20 Range 255"));
1144 test(SIntFindInOrderTest(20,NUM_TESTS,255)==KErrNone);
1145 test.Next(_L("Count 100 Range 4095"));
1146 test(SIntFindInOrderTest(100,NUM_TESTS,4095)==KErrNone);
1147 test.Next(_L("Squares"));
1148 test(SIntFindInOrderTest2()==KErrNone);
1150 test.Next(_L("InsertInOrder tests..."));
1151 test.Next(_L("Count 10 Range 15"));
1152 test(SIntInsertInOrderTest(10,NUM_TESTS,15)==KErrNone);
1153 test.Next(_L("Count 20 Range 255"));
1154 test(SIntInsertInOrderTest(20,NUM_TESTS,255)==KErrNone);
1155 test.Next(_L("Count 100 Range all"));
1156 test(SIntInsertInOrderTest(100,NUM_TESTS,-1)==KErrNone);
1157 test.Next(_L("Squares"));
1158 test(SIntInsertInOrderTest2()==KErrNone);
1160 test.Next(_L("Sort tests..."));
1161 test.Next(_L("Count 10 Range 15"));
1162 test(SIntSortTest(10,NUM_TESTS,15)==KErrNone);
1163 test.Next(_L("Count 20 Range 255"));
1164 test(SIntSortTest(20,NUM_TESTS,255)==KErrNone);
1165 test.Next(_L("Count 100 Range all"));
1166 test(SIntSortTest(100,NUM_TESTS,-1)==KErrNone);
1168 test.Next(_L("IntSpecificFindTests..."));
1169 test(IntSpecificFindTests1()==KErrNone);
1170 test(IntSpecificFindTests2(100, 10, 15)==KErrNone);
1171 test(IntSpecificFindTests2(100, 10, 127)==KErrNone);
1173 test.Next(_L("SIntSpecificFindTests..."));
1174 test(SIntSpecificFindTests2(100, 10, 15)==KErrNone);
1175 test(SIntSpecificFindTests2(100, 10, 127)==KErrNone);