247963c0843e44941882a004cfcebcebbd65fb98
[occt.git] / src / QANCollection / QANCollection_FuncMaps.hxx
1 // Created on: 2002-04-30
2 // Created by: Alexander KARTOMIN (akm)
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef QANCollection_FuncMaps_HeaderFile
17 #define QANCollection_FuncMaps_HeaderFile
18
19 // ===================== Test methods of Map type =============================
20 ////////////////////////////////void TestMap  (QANCollection_Map& theM)
21 void TestMap  (QANCollection_MapFunc& theM)
22 {
23   // Extent
24   Standard_Integer iExt=theM.Extent();
25   Standard_Integer i;
26
27   printf ("Info: testing Map(l=%d)\n", iExt);
28   theM.Statistics(cout);
29   // Resize
30   theM.ReSize(8);
31   theM.Statistics(cout);
32   cout.flush();
33   // Constructor
34   ////////////////////////////////QANCollection_Map aM;
35   QANCollection_MapFunc aM;
36   // Add
37   Key1Type aKey;
38   for (i=0; i<8; i++)
39   {
40     Random (aKey);
41     aM.Add (aKey);
42   }
43   // Contains, Remove
44   if (!aM.Contains(aKey))
45   {
46     printf("Error   : map says that it does not contain its key ");
47     PrintItem(aKey);
48   }
49   else
50   {
51     aM.Remove(aKey);
52     printf("      successfully removed item, l=%d\n", aM.Size());
53   }
54   // Copy constructor (including operator=)
55   ////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM);
56   QANCollection_MapFunc aM2 = QANCollection_MapFunc(aM);
57   // Assign
58   AssignCollection (aM2,theM);
59
60   // Clear
61   aM.Clear();
62 }
63
64 // ===================== Test methods of DataMap type =========================
65 ////////////////////////////////void TestDataMap  (QANCollection_DataMap& theM)
66 void TestDataMap  (QANCollection_DataMapFunc& theM)
67 {
68   // Extent
69   Standard_Integer iExt=theM.Extent();
70   Standard_Integer i;
71
72   printf ("Info: testing DataMap(l=%d)\n", iExt);
73   theM.Statistics(cout);
74   // Resize
75   theM.ReSize(8);
76   theM.Statistics(cout);
77   cout.flush();
78   // Constructor
79   ////////////////////////////////QANCollection_DataMap aM;
80   QANCollection_DataMapFunc aM;
81   // Bind, Find, ChangeFind, ()
82   Key1Type aKey;
83   ItemType anItem;
84   for (i=0; i<8; i++)
85   {
86     Random (aKey);
87     Random (anItem);
88     aM.Bind (aKey, anItem);
89     PrintItem(aM.Find(aKey));
90     Random(aM(aKey));
91   }
92   // IsBound, UnBind
93   if (!aM.IsBound(aKey))
94   {
95     printf("Error   : map says that it does not contain its key ");
96     PrintItem(aKey);
97   }
98   else
99   {
100     aM.UnBind(aKey);
101     printf("      successfully unbound the key, l=%d\n", aM.Size());
102   }
103   // Copy constructor (including operator=)
104   ////////////////////////////////theM = QANCollection_DataMap(aM);
105   theM = QANCollection_DataMapFunc(aM);
106   // Assign - prohibited
107   // AssignCollection (aM2,theM);
108   printCollection (theM, "DataMap:");
109
110   // Clear
111   aM.Clear();
112 }
113
114
115 // ===================== Test methods of DoubleMap type =======================
116 ////////////////////////////////void TestDoubleMap  (QANCollection_DoubleMap& theM)
117 void TestDoubleMap  (QANCollection_DoubleMapFunc& theM)
118 {
119   // Extent
120   Standard_Integer iExt=theM.Extent();
121   Standard_Integer i;
122
123   printf ("Info: testing DoubleMap(l=%d)\n", iExt);
124   theM.Statistics(cout);
125   // Resize
126   theM.ReSize(8);
127   theM.Statistics(cout);
128   cout.flush();
129   // Constructor
130   ////////////////////////////////QANCollection_DoubleMap aM;
131   QANCollection_DoubleMapFunc aM;
132   // Bind, Find?, 
133   Key1Type aKey1;
134   Key2Type aKey2;
135   for (i=0; i<8; i++)
136   {
137     Random (aKey1);
138     Random (aKey2);
139     aM.Bind (aKey1, aKey2);
140     PrintItem(aM.Find1(aKey1));
141     if (!aM.IsBound1(aKey1))
142     {
143       printf("Error   : map says that it does not contain its key ");
144       PrintItem(aKey1);
145     }
146     PrintItem(aM.Find2(aKey2));
147     if (!aM.IsBound2(aKey2))
148     {
149       printf("Error   : map says that it does not contain its key ");
150       PrintItem(aKey2);
151     }
152   }
153   // AreBound, UnBind
154   if (!aM.AreBound(aKey1,aKey2))
155   {
156     printf("Error   : map says that it does not contain its keys ");
157     PrintItem(aKey1);
158     PrintItem(aKey2);
159   }
160   else
161   {
162     if (aM.UnBind2(aKey2))
163       printf("      successfully unbound the key, l=%d\n", aM.Size());
164     if (aM.UnBind1(aKey1))
165       printf("Error   : unbound both keys?!\n");
166   }
167   // Copy constructor (including operator=)
168   ////////////////////////////////theM = QANCollection_DoubleMap(aM);
169   theM = QANCollection_DoubleMapFunc(aM);
170   // Assign - prohibited
171   // AssignCollection (aM2,theM);
172   printCollection (theM, "DoubleMap:");
173
174   // Clear
175   aM.Clear();
176 }
177
178 // ===================== Test methods of IndexedMap type ======================
179 ////////////////////////////////void TestIndexedMap  (QANCollection_IndexedMap& theM)
180 void TestIndexedMap  (QANCollection_IndexedMapFunc& theM)
181 {
182   // Extent
183   Standard_Integer iExt=theM.Extent();
184   Standard_Integer i;
185
186   printf ("Info: testing IndexedMap(l=%d)\n", iExt);
187   theM.Statistics(cout);
188   // Resize
189   theM.ReSize(8);
190   theM.Statistics(cout);
191   cout.flush();
192   // Constructor
193   ////////////////////////////////QANCollection_IndexedMap aM;
194   QANCollection_IndexedMapFunc aM;
195   // Add, FindKey, FindIndex
196   Key1Type aKey;
197   for (i=0; i<8; i++)
198   {
199     Random (aKey);
200     aM.Add (aKey);
201     Standard_Integer iIndex=aM.FindIndex(aKey);
202     printf ("     added a key, i=%d, k=",iIndex);
203     PrintItem(aM(iIndex));
204   }
205   // Contains, Remove
206   if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey))))
207   {
208     printf("Error   : map says that it does not contain its key ");
209     PrintItem(aKey);
210   }
211   else
212   {
213     aM.RemoveLast();
214     printf("      successfully removed item, l=%d\n", aM.Size());
215   }
216   // Substitute
217   Random(aKey);
218   aM.Substitute(1,aKey);
219   // Copy constructor (including operator=)
220   ////////////////////////////////QANCollection_IndexedMap aM2 = QANCollection_IndexedMap(aM);
221   QANCollection_IndexedMapFunc aM2 = QANCollection_IndexedMapFunc(aM);
222   // Assign
223   AssignCollection (aM2,theM);
224
225   // Clear
226   aM.Clear();
227 }
228
229 // ===================== Test methods of IndexedDataMap type ==================
230 ////////////////////////////////void TestIndexedDataMap  (QANCollection_IDMap& theM)
231 void TestIndexedDataMap  (QANCollection_IDMapFunc& theM)
232 {
233   // Extent
234   Standard_Integer iExt=theM.Extent();
235   Standard_Integer i;
236
237   printf ("Info: testing IndexedDataMap(l=%d)\n", iExt);
238   theM.Statistics(cout);
239   // Resize
240   theM.ReSize(8);
241   theM.Statistics(cout);
242   cout.flush();
243   // Constructor
244   ////////////////////////////////QANCollection_IDMap aM;
245   QANCollection_IDMapFunc aM;
246   // Add, FindKey, FindIndex, FindFromIndex, Change..., ()
247   Key1Type aKey;
248   ItemType anItem;
249   for (i=0; i<8; i++)
250   {
251     Random (aKey);
252     Random (anItem);
253     aM.Add (aKey, anItem);
254     Standard_Integer iIndex=aM.FindIndex(aKey);
255     printf ("     added a key, i=%d, k=",iIndex);
256     PrintItem(aM.FindKey(iIndex));
257     PrintItem(aM(iIndex));
258     Random(aM.ChangeFromIndex(iIndex));
259   }
260   // Contains, Remove, FindFromKey
261   if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey))))
262   {
263     printf("Error   : map says that it does not contain its key ");
264     PrintItem(aKey);
265   }
266   else
267   {
268     anItem = aM.FindFromKey(aKey);
269     aM.RemoveLast();
270     printf("      successfully removed item, l=%d\n", aM.Size());
271   }
272   // Substitute
273   Random(aKey);
274   aM.Substitute (1, aKey, anItem);
275   // Copy constructor (including operator=)
276   ////////////////////////////////theM = QANCollection_IDMap(aM);
277   theM = QANCollection_IDMapFunc(aM);
278   // Assign - prohibited
279   // AssignCollection (aM2,theM);
280   printCollection (theM, "DoubleMap:");
281
282   // Clear
283   aM.Clear();
284 }
285
286
287 #endif