150f78a940e2980e26238edb93f7b5afbb8bc61a
[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 Set type =============================
74 ////////////////////////////////void TestSet (QANCollection_Set& theS)
75 void TestSet (QANCollection_SetFunc& theS)
76 {
77   // Extent
78   Standard_Integer iExt=theS.Extent();
79   Standard_Integer i;
80
81   printf ("Info: testing Set(%d)\n", iExt);
82   Key2Type anItem;
83   // Constructor, Add
84   ////////////////////////////////QANCollection_Set aSet1, aSet2, aSet;
85   QANCollection_SetFunc aSet1, aSet2, aSet;
86   for (i=1; i<=8; i++)
87   {
88     Random(anItem);
89     aSet1.Add(anItem);
90     if (i>4)
91       aSet2.Add(anItem);
92   }
93   for (i=1; i<=4; i++)
94   {
95     Random(anItem);
96     aSet2.Add(anItem);
97   }
98   if (!aSet2.Contains(anItem))
99     printf ("Error   : set sais it does not contain its item\n");
100   // operator=, Union, Difference, Intersection
101   aSet = aSet1;
102   printCollection(aSet2,"Set2");
103   aSet1.Union(aSet2);
104   printCollection(aSet1,"Union");
105   if (!aSet1.IsAProperSubset(aSet2))
106     printf ("Error   : not a proper subset?\n");
107   if (!aSet1.IsAProperSubset(aSet2))
108     printf ("Error   : not a subset?!\n");
109   aSet1.Intersection(aSet);
110   printCollection(aSet,"Intersection");
111   aSet1.Difference(aSet2);
112   printCollection(aSet1,"Difference");
113
114   // operator=
115   ////////////////////////////////Handle(QANCollection_HSet) aHS = new QANCollection_HSet(aSet);
116   Handle(QANCollection_HSetFunc) aHS = new QANCollection_HSetFunc(aSet);
117
118   // Assign
119   AssignCollection (aHS->ChangeSet(), theS);
120
121   // Clear
122   aSet.Clear();
123 }
124
125 // ===================== Test methods of Sequence type ========================
126 ////////////////////////////////void TestSequence (QANCollection_Sequence& theS)
127 void TestSequence (QANCollection_SequenceFunc& theS)
128 {
129   Standard_Integer i;
130
131   printf ("Info: testing Sequence\n");
132   // Append(2)
133   ItemType anItem;
134   ////////////////////////////////QANCollection_Sequence aS, aS1;
135   QANCollection_SequenceFunc aS, aS1;
136   // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), 
137   // Remove, RemoveFirst, First, Last
138   for (i=0; i<4; i++)
139   {
140     Random (anItem);
141     aS.Append (anItem); // #1
142     aS.Append (aS1);    // #2
143     Random (anItem);
144     aS1.Prepend (anItem); // #3
145     aS1.Prepend (aS);     // #4
146     if (theS.Length() > 0)
147     {
148       Random (anItem);
149       theS.InsertBefore (1, anItem); // #5
150       theS.InsertBefore (2, aS1);    // #6
151       Random (anItem);
152       theS.InsertAfter (1, anItem); // #7
153       theS.InsertAfter (2, aS);     // #8
154       theS.Remove (1);  // #9
155       if (theS.Length() > 0)
156         theS.Remove(1); // #10
157     }
158     else
159     {
160       theS.Prepend (anItem);
161       PrintItem(theS.First());
162       PrintItem(theS.Last());
163     }
164   }
165
166   // ()
167   PrintItem(theS(1));
168
169   // Handle, Split
170   ////////////////////////////////Handle(QANCollection_HSequence) aHS = new QANCollection_HSequence(aS1);
171   Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1);
172   theS.Split (3, aHS->ChangeSequence());
173
174   // Assign
175   AssignCollection (theS, aS);
176
177   // Clear
178   aS.Clear();
179 }
180
181 #endif