Commit e5f0a642 authored by Kenneth Leiter's avatar Kenneth Leiter

ENH: Remove trailing whitespace when convert arrays to strings in XdmfArray.

Fix comparisons in tests to not contain the trailing whitespace.
parent f46b9dc3
......@@ -193,26 +193,37 @@ public:
{
}
template<typename T, typename U>
std::string
getValuesString(const char * const array,
getValuesString(const T * const array,
const int numValues) const
{
const unsigned int lastIndex = numValues-1;
if(lastIndex < 0) {
return "";
}
std::stringstream toReturn;
for(int i=0; i<numValues; ++i) {
toReturn << (int)array[i] << " ";
for(unsigned int i=0; i<lastIndex; ++i) {
toReturn << (U)array[i] << " ";
}
toReturn << (U)array[lastIndex];
return toReturn.str();
}
std::string
getValuesString(const char * const array,
const int numValues) const
{
return getValuesString<char, int>(array, numValues);
}
std::string
getValuesString(const unsigned char * const array,
const int numValues) const
{
std::stringstream toReturn;
for(int i=0; i<numValues; ++i) {
toReturn << (int)array[i] << " ";
}
return toReturn.str();
return getValuesString<unsigned char, int>(array, numValues);
}
template<typename T>
......@@ -220,11 +231,7 @@ public:
getValuesString(const T * const array,
const int numValues) const
{
std::stringstream toReturn;
for(int i=0; i<numValues; ++i) {
toReturn << array[i] << " ";
}
return toReturn.str();
return getValuesString<T, T>(array, numValues);
}
template<typename T>
......
......@@ -21,11 +21,11 @@ int main(int, char *)
std::vector<unsigned int> dimensions = array->getDimensions();
assert(dimensions.size() == 1);
assert(dimensions[0] == 0);
assert(array->getDimensionsString().compare("0 ") == 0);
assert(array->getDimensionsString().compare("0") == 0);
array->insert(0, &values[0], 4, 1, 1);
assert(array->getSize() == 4);
assert(array->getArrayType() == XdmfArrayType::Int32());
assert(array->getValuesString().compare("1 2 3 4 ") == 0);
assert(array->getValuesString().compare("1 2 3 4") == 0);
const int * const arrayPointer =
(const int * const)array->getValuesInternal();
assert(arrayPointer[0] == 1);
......@@ -53,7 +53,7 @@ int main(int, char *)
array2->insert(0, &values[0], 2, 2, 1);
assert(array2->getSize() == 3);
assert(array2->getArrayType() == XdmfArrayType::Int32());
assert(array2->getValuesString().compare("1 0 2 ") == 0);
assert(array2->getValuesString().compare("1 0 2") == 0);
storedValues = array2->getValuesInternal<int>();
assert((*storedValues)[0] == 1);
assert((*storedValues)[1] == 0);
......@@ -66,7 +66,7 @@ int main(int, char *)
array3->insert(0, &values[0], 2, 1, 2);
assert(array3->getSize() == 2);
assert(array3->getArrayType() == XdmfArrayType::Int32());
assert(array3->getValuesString().compare("1 3 ") == 0);
assert(array3->getValuesString().compare("1 3") == 0);
storedValues = array3->getValuesInternal<int>();
assert((*storedValues)[0] == 1);
assert((*storedValues)[1] == 3);
......@@ -77,7 +77,7 @@ int main(int, char *)
boost::shared_ptr<XdmfArray> array4 = XdmfArray::New();
array4->insert(0, &values[0], 2, 2, 2);
assert(array4->getSize() == 3);
assert(array4->getValuesString().compare("1 0 3 ") == 0);
assert(array4->getValuesString().compare("1 0 3") == 0);
storedValues = array4->getValuesInternal<int>();
assert((*storedValues)[0] == 1);
assert((*storedValues)[1] == 0);
......@@ -120,7 +120,7 @@ int main(int, char *)
array5->setValuesInternal(values, 2, 0);
assert(array5->getSize() == 2);
assert(array5->getArrayType() == XdmfArrayType::Int32());
assert(array5->getValuesString().compare("1 2 ") == 0);
assert(array5->getValuesString().compare("1 2") == 0);
const int * const array5Pointer =
(const int * const)array5->getValuesInternal();
assert(array5Pointer[0] == 1);
......@@ -134,11 +134,11 @@ int main(int, char *)
*/
array5->setValuesInternal(&values[1], 3, 0);
assert(array5->getSize() == 3);
assert(array5->getValuesString().compare("2 3 4 ") == 0);
assert(array5->getValuesString().compare("2 3 4") == 0);
int zero = 0;
array5->insert(3, &zero, 1, 1, 0);
assert(array5->getSize() == 4);
assert(array5->getValuesString().compare("2 3 4 0 ") == 0);
assert(array5->getValuesString().compare("2 3 4 0") == 0);
/**
* Set and Ownership transfer
......@@ -150,7 +150,7 @@ int main(int, char *)
array5->setValuesInternal(doubleValues, 3, 1);
assert(array5->getSize() == 3);
assert(array5->getArrayType() == XdmfArrayType::Float64());
assert(array5->getValuesString().compare("0 1.1 10.1 ") == 0);
assert(array5->getValuesString().compare("0 1.1 10.1") == 0);
//
// SHARED ASSIGNMENTS
......@@ -169,7 +169,7 @@ int main(int, char *)
array6->setValuesInternal(values2);
assert(array6->getSize() == 5);
assert(array6->getArrayType() == XdmfArrayType::Int8());
assert(array6->getValuesString().compare("-2 -1 0 1 2 ") == 0);
assert(array6->getValuesString().compare("-2 -1 0 1 2") == 0);
// Assert we have the same values!
boost::shared_ptr<std::vector<char> > storedValues2 =
array6->getValuesInternal<char>();
......@@ -182,7 +182,7 @@ int main(int, char *)
// Now modify original array
values2->push_back(8);
assert(array6->getSize() == 6);
assert(array6->getValuesString().compare("-2 -1 0 1 2 8 ") == 0);
assert(array6->getValuesString().compare("-2 -1 0 1 2 8") == 0);
// Assert we have the same values!
i = 0;
for(std::vector<char>::const_iterator iter = storedValues2->begin();
......@@ -254,11 +254,11 @@ int main(int, char *)
boost::shared_ptr<XdmfArray> array8 = XdmfArray::New();
array8->insert(0, &values[0], 4, 1, 1);
array8->resize(5, 0);
assert(array8->getValuesString().compare("1 2 3 4 0 ") == 0);
assert(array8->getValuesString().compare("1 2 3 4 0") == 0);
array8->resize(3, 0);
assert(array8->getValuesString().compare("1 2 3 ") == 0);
assert(array8->getValuesString().compare("1 2 3") == 0);
array8->resize(8, 1.1);
assert(array8->getValuesString().compare("1 2 3 1 1 1 1 1 ") == 0);
assert(array8->getValuesString().compare("1 2 3 1 1 1 1 1") == 0);
/**
* Reserve / Capacity
......
......@@ -17,14 +17,14 @@ int main(int, char *)
assert(dimensions.size() == 1);
assert(dimensions[0] == 2);
std::string dimensionsString = array->getDimensionsString();
assert(dimensionsString.compare("2 ") == 0);
assert(dimensionsString.compare("2") == 0);
array->resize<unsigned int>(3);
assert(array->getSize() == 3);
dimensions = array->getDimensions();
assert(dimensions.size() == 1);
assert(dimensions[0] == 3);
dimensionsString = array->getDimensionsString();
assert(dimensionsString.compare("3 ") == 0);
assert(dimensionsString.compare("3") == 0);
//
// Create 2D arrays
......@@ -38,7 +38,7 @@ int main(int, char *)
assert(dimensions.size() == 2);
assert(dimensions[0] == 2 && dimensions[1] == 2);
dimensionsString = array2->getDimensionsString();
assert(dimensionsString.compare("2 2 ") == 0);
assert(dimensionsString.compare("2 2") == 0);
std::vector<unsigned int> newDimensions2(3,3);
array2->resize<unsigned short>(newDimensions2);
assert(array2->getSize() == 27);
......@@ -46,7 +46,7 @@ int main(int, char *)
assert(dimensions.size() == 3);
assert(dimensions[0] == 3 && dimensions[1] == 3 && dimensions[2] == 3);
dimensionsString = array2->getDimensionsString();
assert(dimensionsString.compare("3 3 3 ") == 0);
assert(dimensionsString.compare("3 3 3") == 0);
int values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
array2->insert(0, &values[0], 11);
......
......@@ -8,18 +8,18 @@ int main(int, char *)
boost::shared_ptr<XdmfArray> array = XdmfArray::New();
array->insert(0, &values[0], 4, 1, 1);
assert(array->getSize() == 4);
assert(array->getValuesString().compare("1 2 3 4 ") == 0);
assert(array->getValuesString().compare("1 2 3 4") == 0);
boost::shared_ptr<XdmfHDF5Writer> writer = XdmfHDF5Writer::New("test.h5");
array->accept(writer);
assert(array->getSize() == 4);
assert(array->getValuesString().compare("1 2 3 4 ") == 0);
assert(array->getValuesString().compare("1 2 3 4") == 0);
array->release();
assert(array->getValuesString() == "");
assert(array->getSize() == 4);
array->read();
assert(array->getValuesString().compare("1 2 3 4 ") == 0);
assert(array->getValuesString().compare("1 2 3 4") == 0);
}
......@@ -34,7 +34,7 @@ int main(int, char *)
vy,
vz);
assert(grid->getDimensions()->getValuesString().compare("4 3 3 ") == 0);
assert(grid->getDimensions()->getValuesString().compare("4 3 3") == 0);
assert(vx == grid->getCoordinates(0));
assert(vy == grid->getCoordinates(1));
assert(vz == grid->getCoordinates(2));
......
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