1f07b676ddc955b8e79344e7d15b34862482a4b1
[occt.git] / src / QANCollection / QANCollection_FuncLists.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_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 Stack type ===========================
74 ////////////////////////////////void TestStack (QANCollection_Stack& theS)
75 void TestStack (QANCollection_StackFunc& theS)
76 {
77   // Depth
78   Standard_Integer iDep=theS.Depth();
79   Standard_Integer i;
80
81   printf ("Info: testing Stack(%d)\n", iDep);
82   // Push, Pop, Top, ChangeTop
83   ItemType anItem;
84   ////////////////////////////////QANCollection_Stack aS;
85   QANCollection_StackFunc aS;
86   for (i=0; i<4; i++)
87   {
88     Random (anItem);
89     aS.Push (anItem);
90     Random(aS.ChangeTop());
91     Random (anItem);
92     aS.Push (anItem);
93     PrintItem(aS.Top());
94     aS.Pop();
95   }
96   // Copy constructor + operator=
97   ////////////////////////////////theS = QANCollection_Stack(aS);
98   theS = QANCollection_StackFunc(aS);
99
100   // Assign
101   AssignCollection (theS, aS);
102
103   // Clear
104   aS.Clear();
105 }
106
107 // ===================== Test methods of Set type =============================
108 ////////////////////////////////void TestSet (QANCollection_Set& theS)
109 void TestSet (QANCollection_SetFunc& theS)
110 {
111   // Extent
112   Standard_Integer iExt=theS.Extent();
113   Standard_Integer i;
114
115   printf ("Info: testing Set(%d)\n", iExt);
116   Key2Type anItem;
117   // Constructor, Add
118   ////////////////////////////////QANCollection_Set aSet1, aSet2, aSet;
119   QANCollection_SetFunc aSet1, aSet2, aSet;
120   for (i=1; i<=8; i++)
121   {
122     Random(anItem);
123     aSet1.Add(anItem);
124     if (i>4)
125       aSet2.Add(anItem);
126   }
127   for (i=1; i<=4; i++)
128   {
129     Random(anItem);
130     aSet2.Add(anItem);
131   }
132   if (!aSet2.Contains(anItem))
133     printf ("Error   : set sais it does not contain its item\n");
134   // operator=, Union, Difference, Intersection
135   aSet = aSet1;
136   printCollection(aSet2,"Set2");
137   aSet1.Union(aSet2);
138   printCollection(aSet1,"Union");
139   if (!aSet1.IsAProperSubset(aSet2))
140     printf ("Error   : not a proper subset?\n");
141   if (!aSet1.IsAProperSubset(aSet2))
142     printf ("Error   : not a subset?!\n");
143   aSet1.Intersection(aSet);
144   printCollection(aSet,"Intersection");
145   aSet1.Difference(aSet2);
146   printCollection(aSet1,"Difference");
147
148   // operator=
149   ////////////////////////////////Handle(QANCollection_HSet) aHS = new QANCollection_HSet(aSet);
150   Handle(QANCollection_HSetFunc) aHS = new QANCollection_HSetFunc(aSet);
151
152   // Assign
153   AssignCollection (aHS->ChangeSet(), theS);
154
155   // Clear
156   aSet.Clear();
157 }
158
159 // ===================== Test methods of SList type ===========================
160 ////////////////////////////////void TestSList (QANCollection_SList&     theSL)
161 void TestSList (QANCollection_SListFunc&     theSL)
162 {
163   printf ("Info: testing SList\n");
164   ItemType anItem;
165   ////////////////////////////////QANCollection_SList aSL, aSL1;
166   QANCollection_SListFunc aSL, aSL1;
167
168   // Construct, Constructed, operator=, IsEmpty
169   Random(anItem);
170   aSL.Construct(anItem);
171   Random(anItem);
172   aSL1 = aSL.Constructed(anItem);
173   if (aSL.IsEmpty())
174     printf ("Error   : SList must not be empty\n");
175   printCollection(aSL1,"aSL1");
176   
177   Random(anItem);
178   aSL.Construct(anItem);
179   // SetTail
180   aSL.SetTail(aSL1);
181   printCollection(aSL,"aSL");
182
183   // ChangeValue
184   Random(aSL1.Tail().ChangeValue());
185   // ChangeTail, ToTail
186   Random(anItem);
187   theSL.Construct(anItem);
188   printCollection(theSL,"theSL");
189   theSL.ChangeTail() = aSL;
190   printCollection(theSL,"theSL");
191
192   // Assign
193   AssignCollection (aSL, theSL);
194
195   // Clear
196   aSL.Clear();
197 }
198
199 // ===================== Test methods of Sequence type ========================
200 ////////////////////////////////void TestSequence (QANCollection_Sequence& theS)
201 void TestSequence (QANCollection_SequenceFunc& theS)
202 {
203   Standard_Integer i;
204
205   printf ("Info: testing Sequence\n");
206   // Append(2)
207   ItemType anItem;
208   ////////////////////////////////QANCollection_Sequence aS, aS1;
209   QANCollection_SequenceFunc aS, aS1;
210   // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), 
211   // Remove, RemoveFirst, First, Last
212   for (i=0; i<4; i++)
213   {
214     Random (anItem);
215     aS.Append (anItem); // #1
216     aS.Append (aS1);    // #2
217     Random (anItem);
218     aS1.Prepend (anItem); // #3
219     aS1.Prepend (aS);     // #4
220     if (theS.Length() > 0)
221     {
222       Random (anItem);
223       theS.InsertBefore (1, anItem); // #5
224       theS.InsertBefore (2, aS1);    // #6
225       Random (anItem);
226       theS.InsertAfter (1, anItem); // #7
227       theS.InsertAfter (2, aS);     // #8
228       theS.Remove (1);  // #9
229       if (theS.Length() > 0)
230         theS.Remove(1); // #10
231     }
232     else
233     {
234       theS.Prepend (anItem);
235       PrintItem(theS.First());
236       PrintItem(theS.Last());
237     }
238   }
239
240   // ()
241   PrintItem(theS(1));
242
243   // Handle, Split
244   ////////////////////////////////Handle(QANCollection_HSequence) aHS = new QANCollection_HSequence(aS1);
245   Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1);
246   theS.Split (3, aHS->ChangeSequence());
247
248   // Assign
249   AssignCollection (theS, aS);
250
251   // Clear
252   aS.Clear();
253 }
254
255 #endif