1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 \*---------------------------------------------------------------------------*/
31 #include "IOstreams.H"
32 #include "PackedBoolList.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 int main(int argc, char *argv[])
41 Info<< "PackedList max_bits() = " << PackedList<>::max_bits() << nl;
43 Info<< "\ntest allocation with value\n";
44 PackedList<3> list1(5,1);
47 Info<< "\ntest assign uniform value\n";
51 Info<< "\ntest assign uniform value (with overflow)\n";
55 Info<< "\ntest zero\n";
59 Info<< "\ntest set() with default argument (max_value)\n";
63 Info<< "\ntest assign between references\n";
68 Info<< "\ntest assign between references, with chaining\n";
69 list1[0] = list1[4] = 1;
72 Info<< "\ntest assign between references, with chaining and auto-vivify\n";
73 list1[1] = list1[8] = list1[10] = list1[14] = 2;
77 Info<< "\ntest operator== between references\n";
78 if (list1[1] == list1[8])
80 Info<< "[1] == [8] (expected)\n";
84 Info<< "[1] != [8] (unexpected)\n";
87 if (list1[0] != list1[1])
89 Info<< "[0] != [1] (expected)\n";
93 Info<< "[0] == [1] (unexpected)\n";
96 Info<< "\ntest operator== with iterator\n";
98 PackedList<3>::iterator iter = list1[1];
100 if (iter != list1[8])
102 Info<< "iter != [8] (expected)\n";
106 Info<< "iter == [8] (unexpected)\n";
109 if (*iter != list1[8])
111 Info<< "*iter != [8] (unexpected)\n";
115 Info<< "*iter == [8] (expected)\n";
121 const PackedList<3>& constLst = list1;
122 Info<< "\ntest operator[] const with out-of-range index\n";
123 constLst.print(Info);
126 Info<< "[20] is true (unexpected)\n";
130 Info<< "[20] is false (expected) list size should be unchanged (const)\n";
132 constLst.print(Info);
134 Info<< "\ntest operator[] non-const with out-of-range index\n";
137 Info<< "[20] is true (unexpected)\n";
141 Info<< "[20] is false (expected) but list was resized?? (non-const)\n";
147 Info<< "\ntest operator[] with out-of-range index\n";
150 Info<< "[20] is false, as expected\n";
154 Info<< "\ntest resize with value (without reallocation)\n";
155 list1.resize(8, list1.max_value());
158 Info<< "\ntest flip() function\n";
162 Info<< "\nre-flip()\n";
166 Info<< "\ntest set() function\n";
170 Info<< "\ntest assign bool\n";
174 Info<< "\ntest assign bool\n";
178 Info<< "\ntest resize without value (with reallocation)\n";
182 Info<< "\ntest resize with value (with reallocation)\n";
183 list1.resize(25, list1.max_value());
186 Info<< "\ntest resize smaller (should not touch allocation)\n";
190 Info<< "\ntest append() operation\n";
196 Info<< "\ntest reserve() operation\n";
200 Info<< "\ntest shrink() operation\n";
204 Info<< "\ntest setCapacity() operation\n";
205 list1.setCapacity(15);
208 Info<< "\ntest setCapacity() operation\n";
209 list1.setCapacity(100);
212 Info<< "\ntest operator[] assignment\n";
216 Info<< "\ntest operator[] assignment with auto-vivify\n";
217 list1[36] = list1.max_value();
220 Info<< "\ntest setCapacity smaller\n";
221 list1.setCapacity(24);
224 Info<< "\ntest resize much smaller\n";
228 Info<< "\ntest trim\n";
232 // add in some misc values
237 Info<< "\ntest iterator\n";
238 PackedList<3>::iterator iter = list1.begin();
240 iter.print(Info) << "\n";
242 Info<< "iterator:" << iter() << "\n";
248 Info<< "iterator:" << iter() << "\n";
252 Info<< "\ntest get() method\n";
253 Info<< "get(10):" << list1.get(10) << " and list[10]:" << list1[10] << "\n";
256 Info<< "\ntest iterator indexing\n";
258 list1.cend().print(Info) << "\n";
261 Info<< "\ntest assignment of iterator\n";
264 list1.end().print(Info);
265 PackedList<3>::iterator cit = list1[100];
266 Info<< "out-of-range: ";
271 Info<< "out-of-range: ";
279 PackedList<3>::iterator cit = list1[30];
287 Info<< "\ntest operator[] auto-vivify\n";
288 Info<< "size:" << list1.size() << "\n";
290 const unsigned int val = list1[45];
292 Info<< "list[45]:" << val << "\n";
293 Info<< "size after read:" << list1.size() << "\n";
295 list1[45] = list1.max_value();
296 Info<< "size after write:" << list1.size() << "\n";
297 Info<< "list[45]:" << list1[45] << "\n";
298 list1[49] = list1[100];
302 Info<< "\ntest copy constructor + append\n";
303 PackedList<3> list2(list1);
305 Info<< "source list:\n";
307 Info<< "destination list:\n";
310 Info<< "\ntest pattern that fills all bits\n";
311 PackedList<4> list3(8, 8);
313 label pos = list3.size() - 1;
315 list3[pos--] = list3.max_value();
317 list3[pos--] = list3.max_value();
320 Info<< "removed final value: " << list3.remove() << endl;
324 List<bool> list4(4, true);
326 const List<bool>& constLst = list4;
327 Info<< "\ntest operator[] const with out-of-range index\n";
328 Info<< constLst << endl;
331 Info<< "[20] is true (unexpected)\n";
335 Info<< "[20] is false (expected) list size should be unchanged (const)\n";
337 Info<< constLst << endl;
340 Info<< "\n\nDone.\n";
346 // ************************************************************************* //