0024742: Remove rarely used collection classes: SList
[occt.git] / src / QANCollection / QANCollection_FuncLists.hxx
CommitLineData
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)
21void 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
7fd59977 73// ===================== Test methods of Stack type ===========================
74////////////////////////////////void TestStack (QANCollection_Stack& theS)
75void 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)
109void 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
7fd59977 159// ===================== Test methods of Sequence type ========================
160////////////////////////////////void TestSequence (QANCollection_Sequence& theS)
161void TestSequence (QANCollection_SequenceFunc& theS)
162{
163 Standard_Integer i;
164
165 printf ("Info: testing Sequence\n");
166 // Append(2)
167 ItemType anItem;
168 ////////////////////////////////QANCollection_Sequence aS, aS1;
169 QANCollection_SequenceFunc aS, aS1;
170 // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2),
171 // Remove, RemoveFirst, First, Last
172 for (i=0; i<4; i++)
173 {
174 Random (anItem);
175 aS.Append (anItem); // #1
176 aS.Append (aS1); // #2
177 Random (anItem);
178 aS1.Prepend (anItem); // #3
179 aS1.Prepend (aS); // #4
180 if (theS.Length() > 0)
181 {
182 Random (anItem);
183 theS.InsertBefore (1, anItem); // #5
184 theS.InsertBefore (2, aS1); // #6
185 Random (anItem);
186 theS.InsertAfter (1, anItem); // #7
187 theS.InsertAfter (2, aS); // #8
188 theS.Remove (1); // #9
189 if (theS.Length() > 0)
190 theS.Remove(1); // #10
191 }
192 else
193 {
194 theS.Prepend (anItem);
195 PrintItem(theS.First());
196 PrintItem(theS.Last());
197 }
198 }
199
200 // ()
201 PrintItem(theS(1));
202
203 // Handle, Split
204 ////////////////////////////////Handle(QANCollection_HSequence) aHS = new QANCollection_HSequence(aS1);
205 Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1);
206 theS.Split (3, aHS->ChangeSequence());
207
208 // Assign
209 AssignCollection (theS, aS);
210
211 // Clear
212 aS.Clear();
213}
214
215#endif