Commit b76d6b5c authored by Mark Olesen's avatar Mark Olesen
Browse files

STYLE: adjust tests for some updates in methods (issue #876)

parent ba156655
......@@ -41,15 +41,15 @@ using namespace Foam;
template<unsigned nBits>
inline void reportInfo()
{
const unsigned offset = PackedList<nBits>::packing();
const unsigned offset = PackedList<nBits>::elem_per_block;
unsigned useSHL = ((1u << (nBits * offset)) - 1);
unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - nBits * offset));
Info<< nl
<< "PackedList<" << nBits << ">" << nl
<< " max_value: " << PackedList<nBits>::max_value() << nl
<< " packing: " << PackedList<nBits>::packing() << nl
<< " max_value: " << PackedList<nBits>::max_value << nl
<< " packing: " << PackedList<nBits>::elem_per_block << nl
<< " utilization: " << (nBits * offset) << nl;
Info<< " Masking:" << nl
......@@ -61,7 +61,7 @@ inline void reportInfo()
hex(Info);
Info<< " maskLower: "
<< PackedList<nBits>::maskLower(PackedList<nBits>::packing())
<< PackedList<nBits>::mask_lower(PackedList<nBits>::elem_per_block)
<< nl
<< " useSHL: " << useSHL << nl
<< " useSHR: " << useSHR << nl;
......
......@@ -111,16 +111,11 @@ int main(int argc, char *argv[])
list1[4] = list1[2];
report(list1);
Info<< "\ntest assign between references, with chaining\n";
list1[0] = 1;
list1[4] = 1;
report(list1);
Info<< "\ntest assign between references, with chaining and auto-vivify\n";
Info<< "\nset auto-vivify entries\n";
list1[1] = 2;
list1[8] = 2;
list1[10] = 2;
list1[14] = 2;
list1.set(8, 2);
list1.set(10, 2);
list1.set(14, 2);
report(list1);
Info<< "\ntest operator== between references\n";
......@@ -160,39 +155,57 @@ int main(int argc, char *argv[])
report(constLst);
Info<< "\ntest operator[] non-const with out-of-range index\n";
if (list1[20])
// Expect failure
const bool throwingError = FatalError.throwExceptions();
try
{
Info<< "[20] is true (unexpected)\n";
if (list1[20])
{
Info<< "[20] is true (unexpected)\n";
}
else
{
Info<< "[20] is false (expected) but list was resized?? "
<< "(non-const)\n";
}
}
else
catch (Foam::error& err)
{
Info<< "[20] is false (expected) but list was resized?? "
<< "(non-const)\n";
Info<< "Failed (expected) " << err << nl << endl;
}
FatalError.throwExceptions(throwingError);
report(list1);
}
Info<< "\ntest operator[] with out-of-range index\n";
if (!list1[20])
{
Info<< "[20] is false, as expected\n";
Info<< "\ntest operator[] with out-of-range index\n";
// Expect failure
const bool throwingError = FatalError.throwExceptions();
try
{
if (!list1[20])
{
Info<< "[20] is false, as expected for const-access\n";
}
}
catch (Foam::error& err)
{
Info<< "Failed (expected) " << err << nl << endl;
}
FatalError.throwExceptions(throwingError);
report(list1);
}
report(list1);
Info<< "\ntest resize with value (without reallocation)\n";
list1.resize(8, list1.max_value);
report(list1);
//Info<< "\ntest flip() function\n";
//list1.flip();
//report(list1);
//Info<< "\nre-flip()\n";
//list1.flip();
//report(list1);
Info<< "\ntest set() function\n";
list1.set(1, 5);
report(list1);
......@@ -239,19 +252,36 @@ int main(int argc, char *argv[])
list1.setCapacity(100);
report(list1);
Info<< "\ntest operator[] assignment\n";
list1[16] = 5;
report(list1);
// Expect failure
{
const bool throwingError = FatalError.throwExceptions();
Info<< "\ntest operator[] assignment with auto-vivify\n";
try
{
list1[16] = 5;
list1[36] = list1.max_value;
}
catch (Foam::error& err)
{
Info<< "Failed (expected) " << err << nl << endl;
Info<< "Using set(...) instead" << nl;
list1.set(36, list1.max_value);
}
FatalError.throwExceptions(throwingError);
report(list1);
}
Info<< "\ntest operator[] assignment with auto-vivify\n";
list1[36] = list1.max_value;
report(list1);
Info<< "\ntest setCapacity smaller\n";
list1.setCapacity(24);
report(list1);
Info<< "\ntest resize much smaller\n";
Info<< "\ntest resize much larger\n";
list1.resize(150);
report(list1);
......@@ -260,26 +290,24 @@ int main(int argc, char *argv[])
report(list1);
// Add in some misc values
list1[31] = 1;
list1[32] = 2;
list1[33] = 3;
list1.set(31, 1);
list1.set(32, 2);
list1.set(33, 3);
Info<< "\ntest get() method\n";
Info<< "get(10):" << list1.get(10) << " and list[10]:" << list1[10] << "\n";
report(list1);
Info<< "\ntest operator[] auto-vivify\n";
Info<< "\ntest set() auto-vivify\n";
Info<< "size:" << list1.size() << "\n";
const unsigned int val = list1[45];
Info<< "list[45]:" << val << "\n";
Info<< "list[45]:" << list1.get(45) << "\n";
Info<< "size after read:" << list1.size() << "\n";
list1[45] = list1.max_value;
list1.set(45, list1.max_value);
Info<< "size after write:" << list1.size() << "\n";
Info<< "list[45]:" << list1[45] << "\n";
list1[49] = list1[100];
list1.set(49, list1.get(100));
report(list1);
......
......@@ -35,6 +35,7 @@ Description
#include "volFields.H"
#include "Time.H"
#include "OBJstream.H"
#include "fvCFD.H"
using namespace Foam;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment