1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Application
Description
\*---------------------------------------------------------------------------*/
#include "uLabel.H"
#include "IOstreams.H"
#include "PackedBoolList.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
Info<< "PackedList max_bits() = " << PackedList<>::max_bits() << nl;
Info<< "\ntest allocation with value\n";
PackedList<3> list1(5,1);
list1.printInfo(Info, true);
Info<< "\ntest assign uniform value\n";
list1 = 3;
list1.printInfo(Info, true);
Info<< "\ntest assign uniform value (with overflow)\n";
list1 = -1;
list1.printInfo(Info, true);
Info<< "\ntest zero\n";
list1 = 0;
list1.printInfo(Info, true);
Info<< "\ntest set() with default argument (max_value)\n";
list1.set(1);
list1.set(3);
list1.printInfo(Info, true);
Info<< "\ntest unset() with in-range and out-of-range\n";
list1.unset(3);
list1.unset(100000);
list1.printInfo(Info, true);
Info<< "\ntest assign between references\n";
list1[2] = 3;
list1[4] = list1[2];
list1.printInfo(Info, true);
Info<< "\ntest assign between references, with chaining\n";
list1[0] = 1;
list1[4] = 1;
list1.printInfo(Info, true);
Info<< "\ntest assign between references, with chaining and auto-vivify\n";
list1[1] = 2;
list1[8] = 2;
list1[10] = 2;
list1[14] = 2;
list1.printInfo(Info, true);
Info<< "\ntest operator== between references\n";
if (list1[1] == list1[8])
{
Info<< "[1] == [8] (expected)\n";
}
else
{
Info<< "[1] != [8] (unexpected)\n";
}
if (list1[0] != list1[1])
{
Info<< "[0] != [1] (expected)\n";
}
else
{
Info<< "[0] == [1] (unexpected)\n";
}
Info<< "\ntest operator== with iterator\n";
{
PackedList<3>::iterator iter = list1[1];
if (iter != list1[8])
{
Info<< "iter != [8] (expected)\n";
}
else
{
Info<< "iter == [8] (unexpected)\n";
}
if (*iter != list1[8])
{
Info<< "*iter != [8] (unexpected)\n";
}
else
{
Info<< "*iter == [8] (expected)\n";
}
}
{
const PackedList<3>& constLst = list1;
Info<< "\ntest operator[] const with out-of-range index\n";
constLst.printInfo(Info, true);
if (constLst[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) list size should be unchanged "
<< "(const)\n";
}
constLst.printInfo(Info, true);
Info<< "\ntest operator[] non-const with out-of-range index\n";
if (list1[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) but list was resized?? "
<< "(non-const)\n";
}
list1.printInfo(Info, true);
}
Info<< "\ntest operator[] with out-of-range index\n";
if (!list1[20])
{
Info<< "[20] is false, as expected\n";
}
list1.printInfo(Info, true);
Info<< "\ntest resize with value (without reallocation)\n";
list1.resize(8, list1.max_value());
list1.printInfo(Info, true);
Info<< "\ntest flip() function\n";
list1.flip();
list1.printInfo(Info, true);
Info<< "\nre-flip()\n";
list1.flip();
list1.printInfo(Info, true);
Info<< "\ntest set() function\n";
list1.set(1, 5);
list1.printInfo(Info, true);
Info<< "\ntest assign bool\n";
list1 = false;
list1.printInfo(Info, true);
Info<< "\ntest assign bool\n";
list1 = true;
list1.printInfo(Info, true);
Info<< "\ntest resize without value (with reallocation)\n";
list1.resize(12);
list1.printInfo(Info, true);
Info<< "\ntest resize with value (with reallocation)\n";
list1.resize(25, list1.max_value());
list1.printInfo(Info, true);
Info<< "\ntest resize smaller (should not touch allocation)\n";
list1.resize(8);
list1.printInfo(Info, true);
Info<< "\ntest append() operation\n";
list1.append(2);
list1.append(3);
list1.append(4);
list1.printInfo(Info, true);
Info<< "\ntest reserve() operation\n";
list1.reserve(32);
list1.printInfo(Info, true);
Info<< "\ntest shrink() operation\n";
list1.shrink();
list1.printInfo(Info, true);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(15);
list1.printInfo(Info, true);
Info<< "\ntest setCapacity() operation\n";
list1.setCapacity(100);
list1.printInfo(Info, true);
Info<< "\ntest operator[] assignment\n";
list1[16] = 5;
list1.printInfo(Info, true);
Info<< "\ntest operator[] assignment with auto-vivify\n";
list1[36] = list1.max_value();
list1.printInfo(Info, true);
Info<< "\ntest setCapacity smaller\n";
list1.setCapacity(24);
list1.printInfo(Info, true);
Info<< "\ntest resize much smaller\n";
list1.resize(150);
list1.printInfo(Info, true);
Info<< "\ntest trim\n";
list1.trim();
list1.printInfo(Info, true);
// add in some misc values
list1[31] = 1;
list1[32] = 2;
list1[33] = 3;
Info<< "\ntest iterator\n";
PackedList<3>::iterator iter = list1.begin();
Info<< "begin():";
iter.printInfo(Info) << "\n";
Info<< "iterator:" << iter() << "\n";
iter() = 5;
iter.printInfo(Info);
list1.printInfo(Info, true);
iter = list1[31];
Info<< "iterator:" << iter() << "\n";
iter.printInfo(Info);
Info<< "\ntest get() method\n";
Info<< "get(10):" << list1.get(10) << " and list[10]:" << list1[10] << "\n";
list1.printInfo(Info, true);
Info<< "\ntest iterator indexing\n";
Info<< "cend() ";
list1.cend().printInfo(Info) << "\n";
{
Info<< "\ntest assignment of iterator\n";
list1.printInfo(Info, true);
Info<< "cend()\n";
list1.end().printInfo(Info);
PackedList<3>::iterator cit = list1[100];
Info<< "out-of-range: ";
cit.printInfo(Info);
cit = list1[15];
Info<< "in-range: ";
cit.printInfo(Info);
Info<< "out-of-range: ";
cit = list1[1000];
cit.printInfo(Info);
}
for
(
PackedList<3>::iterator cit = list1[30];
cit != list1.end();
++cit
)
{
cit.printInfo(Info);
}
Info<< "\ntest operator[] auto-vivify\n";
Info<< "size:" << list1.size() << "\n";
const unsigned int val = list1[45];
Info<< "list[45]:" << val << "\n";
Info<< "size after read:" << list1.size() << "\n";
list1[45] = list1.max_value();
Info<< "size after write:" << list1.size() << "\n";
Info<< "list[45]:" << list1[45] << "\n";
list1[49] = list1[100];
list1.printInfo(Info, true);
Info<< "\ntest copy constructor + append\n";
PackedList<3> list2(list1);
list2.append(4);
Info<< "source list:\n";
list1.printInfo(Info, true);
Info<< "destination list:\n";
list2.printInfo(Info, true);
Info<< "\ntest pattern that fills all bits\n";
PackedList<4> list3(8, 8);
label pos = list3.size() - 1;
list3[pos--] = list3.max_value();
list3[pos--] = 0;
list3[pos--] = list3.max_value();
list3.printInfo(Info, true);
Info<< "removed final value: " << list3.remove() << endl;
list3.printInfo(Info, true);
Info<<"list: " << list3 << endl;
List<bool> list4(16, false);
{
// fill with some values
forAll(list4, i)
{
list4[i] = i % 3;
}
const UList<bool>& constLst = list4;
Info<< "\ntest operator[] const with out-of-range index\n";
Info<< constLst << endl;
if (constLst[100])
{
Info<< "[100] is true (unexpected)\n";
}
else
{
Info<< "[100] is false (expected) "
<< "list size should be unchanged (const)\n";
}
Info<< constLst << endl;
}
PackedBoolList listb(list4);
Info<< "copied from bool list " << endl;
listb.printInfo(Info, true);
{
labelList indices = listb.used();
Info<< "indices: " << indices << endl;
}
Info<< "\n\nDone.\n";
return 0;
}
// ************************************************************************* //
|