b311480e |
1 | // Created on: 2002-04-30 |
2 | // Created by: Alexander KARTOMIN (akm) |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #ifndef QANCollection_FuncLists_HeaderFile |
17 | #define QANCollection_FuncLists_HeaderFile |
18 | |
19 | // ===================== Test methods of List type ========================== |
20 | ////////////////////////////////void TestList (QANCollection_List& theL) |
21 | void TestList (QANCollection_ListFunc& theL) |
22 | { |
23 | // Extent |
24 | Standard_Integer iExt=theL.Extent(); |
25 | Standard_Integer i; |
26 | |
27 | printf ("Info: testing List(%d)\n", iExt); |
28 | // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), |
29 | // Remove, RemoveFirst, First, Last |
30 | ItemType anItem; |
31 | ////////////////////////////////QANCollection_List aL, aL1; |
32 | QANCollection_ListFunc aL, aL1; |
33 | for (i=0; i<4; i++) |
34 | { |
35 | Random (anItem); |
36 | aL.Append (anItem); // #1 |
37 | aL.Append (aL1); // #2 |
38 | Random (anItem); |
39 | aL1.Prepend (anItem); // #3 |
40 | aL1.Prepend (aL); // #4 |
41 | ////////////////////////////////QANCollection_List::Iterator anI(theL); |
42 | QANCollection_ListFunc::Iterator anI(theL); |
43 | if (anI.More()) |
44 | { |
45 | Random (anItem); |
46 | theL.InsertBefore (anItem, anI); // #5 |
47 | theL.InsertBefore (aL1, anI); // #6 |
48 | Random (anItem); |
49 | theL.InsertAfter (anItem, anI); // #7 |
50 | theL.InsertAfter (aL, anI); // #8 |
51 | theL.Remove (anI); // #9 |
52 | if (theL.Extent() > 0) |
53 | theL.RemoveFirst(); // #10 |
54 | } |
55 | else |
56 | { |
57 | theL.Prepend (anItem); |
58 | PrintItem(theL.First()); |
59 | PrintItem(theL.Last()); |
60 | } |
61 | } |
62 | // Copy constructor + operator= |
63 | ////////////////////////////////aL = QANCollection_List(theL); |
64 | aL = QANCollection_ListFunc(theL); |
65 | |
66 | // Assign |
67 | AssignCollection (theL, aL); |
68 | |
69 | // Clear |
70 | aL.Clear(); |
71 | } |
72 | |
73 | // ===================== Test methods of Queue type =========================== |
74 | ////////////////////////////////void TestQueue (QANCollection_Queue& theQ) |
75 | void TestQueue (QANCollection_QueueFunc& theQ) |
76 | { |
77 | // Length |
78 | Standard_Integer iLen=theQ.Length(); |
79 | Standard_Integer i; |
80 | |
81 | printf ("Info: testing Queue(%d)\n", iLen); |
82 | // Push, Pop, Front, ChangeFront |
83 | ItemType anItem; |
84 | ////////////////////////////////QANCollection_Queue aQ; |
85 | QANCollection_QueueFunc aQ; |
86 | for (i=0; i<4; i++) |
87 | { |
88 | Random (anItem); |
89 | aQ.Push (anItem); |
90 | Random(aQ.ChangeFront()); |
91 | Random (anItem); |
92 | aQ.Push (anItem); |
93 | PrintItem(aQ.Front()); |
94 | aQ.Pop(); |
95 | } |
96 | // Copy constructor + operator= |
97 | ////////////////////////////////theQ = QANCollection_Queue(aQ); |
98 | theQ = QANCollection_QueueFunc(aQ); |
99 | |
100 | // Assign |
101 | AssignCollection (theQ, aQ); |
102 | |
103 | // Clear |
104 | aQ.Clear(); |
105 | } |
106 | |
107 | // ===================== Test methods of Stack type =========================== |
108 | ////////////////////////////////void TestStack (QANCollection_Stack& theS) |
109 | void TestStack (QANCollection_StackFunc& theS) |
110 | { |
111 | // Depth |
112 | Standard_Integer iDep=theS.Depth(); |
113 | Standard_Integer i; |
114 | |
115 | printf ("Info: testing Stack(%d)\n", iDep); |
116 | // Push, Pop, Top, ChangeTop |
117 | ItemType anItem; |
118 | ////////////////////////////////QANCollection_Stack aS; |
119 | QANCollection_StackFunc aS; |
120 | for (i=0; i<4; i++) |
121 | { |
122 | Random (anItem); |
123 | aS.Push (anItem); |
124 | Random(aS.ChangeTop()); |
125 | Random (anItem); |
126 | aS.Push (anItem); |
127 | PrintItem(aS.Top()); |
128 | aS.Pop(); |
129 | } |
130 | // Copy constructor + operator= |
131 | ////////////////////////////////theS = QANCollection_Stack(aS); |
132 | theS = QANCollection_StackFunc(aS); |
133 | |
134 | // Assign |
135 | AssignCollection (theS, aS); |
136 | |
137 | // Clear |
138 | aS.Clear(); |
139 | } |
140 | |
141 | // ===================== Test methods of Set type ============================= |
142 | ////////////////////////////////void TestSet (QANCollection_Set& theS) |
143 | void TestSet (QANCollection_SetFunc& theS) |
144 | { |
145 | // Extent |
146 | Standard_Integer iExt=theS.Extent(); |
147 | Standard_Integer i; |
148 | |
149 | printf ("Info: testing Set(%d)\n", iExt); |
150 | Key2Type anItem; |
151 | // Constructor, Add |
152 | ////////////////////////////////QANCollection_Set aSet1, aSet2, aSet; |
153 | QANCollection_SetFunc aSet1, aSet2, aSet; |
154 | for (i=1; i<=8; i++) |
155 | { |
156 | Random(anItem); |
157 | aSet1.Add(anItem); |
158 | if (i>4) |
159 | aSet2.Add(anItem); |
160 | } |
161 | for (i=1; i<=4; i++) |
162 | { |
163 | Random(anItem); |
164 | aSet2.Add(anItem); |
165 | } |
166 | if (!aSet2.Contains(anItem)) |
167 | printf ("Error : set sais it does not contain its item\n"); |
168 | // operator=, Union, Difference, Intersection |
169 | aSet = aSet1; |
170 | printCollection(aSet2,"Set2"); |
171 | aSet1.Union(aSet2); |
172 | printCollection(aSet1,"Union"); |
173 | if (!aSet1.IsAProperSubset(aSet2)) |
174 | printf ("Error : not a proper subset?\n"); |
175 | if (!aSet1.IsAProperSubset(aSet2)) |
176 | printf ("Error : not a subset?!\n"); |
177 | aSet1.Intersection(aSet); |
178 | printCollection(aSet,"Intersection"); |
179 | aSet1.Difference(aSet2); |
180 | printCollection(aSet1,"Difference"); |
181 | |
182 | // operator= |
183 | ////////////////////////////////Handle(QANCollection_HSet) aHS = new QANCollection_HSet(aSet); |
184 | Handle(QANCollection_HSetFunc) aHS = new QANCollection_HSetFunc(aSet); |
185 | |
186 | // Assign |
187 | AssignCollection (aHS->ChangeSet(), theS); |
188 | |
189 | // Clear |
190 | aSet.Clear(); |
191 | } |
192 | |
193 | // ===================== Test methods of SList type =========================== |
194 | ////////////////////////////////void TestSList (QANCollection_SList& theSL) |
195 | void TestSList (QANCollection_SListFunc& theSL) |
196 | { |
197 | printf ("Info: testing SList\n"); |
198 | ItemType anItem; |
199 | ////////////////////////////////QANCollection_SList aSL, aSL1; |
200 | QANCollection_SListFunc aSL, aSL1; |
201 | |
202 | // Construct, Constructed, operator=, IsEmpty |
203 | Random(anItem); |
204 | aSL.Construct(anItem); |
205 | Random(anItem); |
206 | aSL1 = aSL.Constructed(anItem); |
207 | if (aSL.IsEmpty()) |
208 | printf ("Error : SList must not be empty\n"); |
209 | printCollection(aSL1,"aSL1"); |
210 | |
211 | Random(anItem); |
212 | aSL.Construct(anItem); |
213 | // SetTail |
214 | aSL.SetTail(aSL1); |
215 | printCollection(aSL,"aSL"); |
216 | |
217 | // ChangeValue |
218 | Random(aSL1.Tail().ChangeValue()); |
219 | // ChangeTail, ToTail |
220 | Random(anItem); |
221 | theSL.Construct(anItem); |
222 | printCollection(theSL,"theSL"); |
223 | theSL.ChangeTail() = aSL; |
224 | printCollection(theSL,"theSL"); |
225 | |
226 | // Assign |
227 | AssignCollection (aSL, theSL); |
228 | |
229 | // Clear |
230 | aSL.Clear(); |
231 | } |
232 | |
233 | // ===================== Test methods of Sequence type ======================== |
234 | ////////////////////////////////void TestSequence (QANCollection_Sequence& theS) |
235 | void TestSequence (QANCollection_SequenceFunc& theS) |
236 | { |
237 | Standard_Integer i; |
238 | |
239 | printf ("Info: testing Sequence\n"); |
240 | // Append(2) |
241 | ItemType anItem; |
242 | ////////////////////////////////QANCollection_Sequence aS, aS1; |
243 | QANCollection_SequenceFunc aS, aS1; |
244 | // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), |
245 | // Remove, RemoveFirst, First, Last |
246 | for (i=0; i<4; i++) |
247 | { |
248 | Random (anItem); |
249 | aS.Append (anItem); // #1 |
250 | aS.Append (aS1); // #2 |
251 | Random (anItem); |
252 | aS1.Prepend (anItem); // #3 |
253 | aS1.Prepend (aS); // #4 |
254 | if (theS.Length() > 0) |
255 | { |
256 | Random (anItem); |
257 | theS.InsertBefore (1, anItem); // #5 |
258 | theS.InsertBefore (2, aS1); // #6 |
259 | Random (anItem); |
260 | theS.InsertAfter (1, anItem); // #7 |
261 | theS.InsertAfter (2, aS); // #8 |
262 | theS.Remove (1); // #9 |
263 | if (theS.Length() > 0) |
264 | theS.Remove(1); // #10 |
265 | } |
266 | else |
267 | { |
268 | theS.Prepend (anItem); |
269 | PrintItem(theS.First()); |
270 | PrintItem(theS.Last()); |
271 | } |
272 | } |
273 | |
274 | // () |
275 | PrintItem(theS(1)); |
276 | |
277 | // Handle, Split |
278 | ////////////////////////////////Handle(QANCollection_HSequence) aHS = new QANCollection_HSequence(aS1); |
279 | Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1); |
280 | theS.Split (3, aHS->ChangeSequence()); |
281 | |
282 | // Assign |
283 | AssignCollection (theS, aS); |
284 | |
285 | // Clear |
286 | aS.Clear(); |
287 | } |
288 | |
289 | #endif |