Skip to content
Snippets Groups Projects
Commit 27419297 authored by Nick Draper's avatar Nick Draper
Browse files

clang format re #15164

parent 6f40ba8f
No related branches found
No related tags found
No related merge requests found
...@@ -33,35 +33,36 @@ template <typename T> std::string toString(const boost::shared_ptr<T> &value) { ...@@ -33,35 +33,36 @@ template <typename T> std::string toString(const boost::shared_ptr<T> &value) {
* This simply concatenates the values using a delimiter * This simply concatenates the values using a delimiter
*/ */
template <typename T> template <typename T>
std::string toString(const std::vector<T> &value, std::string
const std::string &delimiter = ",", toString(const std::vector<T> &value, const std::string &delimiter = ",",
typename std::enable_if<!(std::is_integral<T>::value && std::is_arithmetic<T>::value)>::type* = 0) { typename std::enable_if<!(std::is_integral<T>::value &&
std::is_arithmetic<T>::value)>::type * = 0) {
return Strings::join(value.begin(), value.end(), delimiter); return Strings::join(value.begin(), value.end(), delimiter);
} }
/** Specialization for a property of type std::vector of integral types. /** Specialization for a property of type std::vector of integral types.
* This will catch Vectors of int, long, long long etc * This will catch Vectors of int, long, long long etc
* including signed and unsigned types of these. * including signed and unsigned types of these.
* This concatenates the values using a delimiter, * This concatenates the values using a delimiter,
* adjacent items that are precisely 1 away from each other * adjacent items that are precisely 1 away from each other
* will be compressed into a list syntax e.g. 1-5. * will be compressed into a list syntax e.g. 1-5.
*/ */
template <typename T> template <typename T>
std::string toString(const std::vector<T> &value, std::string
const std::string &delimiter = ",", toString(const std::vector<T> &value, const std::string &delimiter = ",",
typename std::enable_if<std::is_integral<T>::value && std::is_arithmetic<T>::value>::type* = 0) { typename std::enable_if<std::is_integral<T>::value &&
std::is_arithmetic<T>::value>::type * = 0) {
return Strings::joinCompress(value.begin(), value.end(), delimiter, "-"); return Strings::joinCompress(value.begin(), value.end(), delimiter, "-");
} }
/** Explicit specialization for a property of type std::vector<bool>. /** Explicit specialization for a property of type std::vector<bool>.
* This will catch Vectors of char, double, float etc. * This will catch Vectors of char, double, float etc.
* This simply concatenates the values using a delimiter * This simply concatenates the values using a delimiter
*/ */
template <> template <>
std::string toString(const std::vector<bool> &value, std::string
const std::string &delimiter, toString(const std::vector<bool> &value, const std::string &delimiter,
typename std::enable_if<std::is_same<bool,bool>::value>::type*) { typename std::enable_if<std::is_same<bool, bool>::value>::type *) {
return Strings::join(value.begin(), value.end(), delimiter); return Strings::join(value.begin(), value.end(), delimiter);
} }
......
...@@ -73,8 +73,8 @@ DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, ...@@ -73,8 +73,8 @@ DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end,
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
/** Join a set or vector of (something that turns into a string) together /** Join a set or vector of (something that turns into a string) together
* into one string, separated by a separator, * into one string, separated by a separator,
* adjacent items that are precisely 1 away from each other * adjacent items that are precisely 1 away from each other
* will be compressed into a list syntax e.g. 1-5. * will be compressed into a list syntax e.g. 1-5.
* Returns an empty string if the range is null. * Returns an empty string if the range is null.
* Does not add the separator after the LAST item. * Does not add the separator after the LAST item.
...@@ -90,8 +90,8 @@ DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, ...@@ -90,8 +90,8 @@ DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end,
*/ */
template <typename ITERATOR_TYPE> template <typename ITERATOR_TYPE>
DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end, DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end,
const std::string &separator = ",", const std::string &separator = ",",
const std::string &listSeparator = "-") { const std::string &listSeparator = "-") {
std::stringstream result; std::stringstream result;
...@@ -101,15 +101,15 @@ DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end, ...@@ -101,15 +101,15 @@ DLLExport std::string joinCompress(ITERATOR_TYPE begin, ITERATOR_TYPE end,
for (i = begin; i != end;) { for (i = begin; i != end;) {
// was this one higher than the last value // was this one higher than the last value
if (i == begin) { if (i == begin) {
//Special case, always include the first value // Special case, always include the first value
result << *i; result << *i;
} else { } else {
//if it is one higher than the last value // if it is one higher than the last value
if (*i == (*previousValue + 1)) { if (*i == (*previousValue + 1)) {
currentSeparator = listSeparator; currentSeparator = listSeparator;
} else { } else {
if (currentSeparator == listSeparator) { if (currentSeparator == listSeparator) {
//add the last value that was the end of the list // add the last value that was the end of the list
result << currentSeparator; result << currentSeparator;
result << *previousValue; result << *previousValue;
currentSeparator = separator; currentSeparator = separator;
......
...@@ -27,7 +27,7 @@ public: ...@@ -27,7 +27,7 @@ public:
TS_ASSERT(typeid(std::vector<int>) == *iProp->type_info()) TS_ASSERT(typeid(std::vector<int>) == *iProp->type_info())
TS_ASSERT(iProp->isDefault()) TS_ASSERT(iProp->isDefault())
TS_ASSERT(iProp->operator()().empty()); TS_ASSERT(iProp->operator()().empty());
TS_ASSERT(!dProp->name().compare("doubleProp")) TS_ASSERT(!dProp->name().compare("doubleProp"))
TS_ASSERT(!dProp->documentation().compare("")) TS_ASSERT(!dProp->documentation().compare(""))
TS_ASSERT(typeid(std::vector<double>) == *dProp->type_info()) TS_ASSERT(typeid(std::vector<double>) == *dProp->type_info())
...@@ -303,65 +303,52 @@ public: ...@@ -303,65 +303,52 @@ public:
void testListShortening() { void testListShortening() {
std::vector<std::string> inputList{ std::vector<std::string> inputList{
"1,2,3", "1,2,3", "-1,0,1", "356,366,367,368,370,371,372,375", "7,6,5,6,7,8,10",
"-1,0,1", "1-9998, 9999, 2000, 20002-29999"};
"356,366,367,368,370,371,372,375", std::vector<std::string> resultList{"1-3", "-1-1",
"7,6,5,6,7,8,10", "356,366-368,370-372,375", "7,6,5-8,10",
"1-9998, 9999, 2000, 20002-29999" "1-9999,2000,20002-29999"};
};
std::vector<std::string> resultList{ TSM_ASSERT("Test Failed for vectors of int",
"1-3", listShorteningwithType<int>(inputList, resultList));
"-1-1", TSM_ASSERT("Test Failed for vectors of long",
"356,366-368,370-372,375", listShorteningwithType<long>(inputList, resultList));
"7,6,5-8,10", TSM_ASSERT("Test Failed for vectors of long long",
"1-9999,2000,20002-29999" listShorteningwithType<long long>(inputList, resultList));
};
TSM_ASSERT("Test Failed for vectors of int", listShorteningwithType<int>(inputList, resultList));
TSM_ASSERT("Test Failed for vectors of long", listShorteningwithType<long>(inputList, resultList));
TSM_ASSERT("Test Failed for vectors of long long", listShorteningwithType<long long>(inputList, resultList));
// explicit test for in32_t with matches det_id_t and spec_id_t // explicit test for in32_t with matches det_id_t and spec_id_t
TSM_ASSERT("Test Failed for vectors of int32_t", listShorteningwithType<int32_t>(inputList, resultList)); TSM_ASSERT("Test Failed for vectors of int32_t",
listShorteningwithType<int32_t>(inputList, resultList));
//unsigned types // unsigned types
std::vector<std::string> inputListUnsigned{ std::vector<std::string> inputListUnsigned{
"1,2,3", "1,2,3", "356,366,367,368,370,371,372,375", "7,6,5,6,7,8,10",
"356,366,367,368,370,371,372,375", "1-9998, 9999, 2000, 20002-29999"};
"7,6,5,6,7,8,10",
"1-9998, 9999, 2000, 20002-29999"
};
std::vector<std::string> resultListUnsigned{ std::vector<std::string> resultListUnsigned{
"1-3", "1-3", "356,366-368,370-372,375", "7,6,5-8,10",
"356,366-368,370-372,375", "1-9999,2000,20002-29999"};
"7,6,5-8,10", TSM_ASSERT("Test Failed for vectors of unsigned int",
"1-9999,2000,20002-29999" listShorteningwithType<unsigned int>(inputListUnsigned,
}; resultListUnsigned));
TSM_ASSERT("Test Failed for vectors of unsigned int", TSM_ASSERT(
listShorteningwithType<unsigned int>(inputListUnsigned, resultListUnsigned)); "Test Failed for vectors of size_t",
TSM_ASSERT("Test Failed for vectors of size_t", listShorteningwithType<size_t>(inputListUnsigned, resultListUnsigned));
listShorteningwithType<size_t>(inputListUnsigned, resultListUnsigned));
// check shortening does not happen for floating point types
//check shortening does not happen for floating point types
std::vector<std::string> inputListFloat{ std::vector<std::string> inputListFloat{
"1.0,2.0,3.0", "1.0,2.0,3.0", "1.0,1.5,2.0,3.0", "-1,0,1",
"1.0,1.5,2.0,3.0",
"-1,0,1",
}; };
std::vector<std::string> resultListFloat{ std::vector<std::string> resultListFloat{
"1,2,3", "1,2,3", "1,1.5,2,3", "-1,0,1",
"1,1.5,2,3",
"-1,0,1",
}; };
TSM_ASSERT("Test Failed for vectors of float", TSM_ASSERT("Test Failed for vectors of float",
listShorteningwithType<float>(inputListFloat, resultListFloat)); listShorteningwithType<float>(inputListFloat, resultListFloat));
TSM_ASSERT("Test Failed for vectors of double", TSM_ASSERT("Test Failed for vectors of double",
listShorteningwithType<double>(inputListFloat, resultListFloat)); listShorteningwithType<double>(inputListFloat, resultListFloat));
} }
template <typename T> template <typename T>
bool listShorteningwithType(const std::vector<std::string>& inputList, bool listShorteningwithType(const std::vector<std::string> &inputList,
const std::vector<std::string>& resultList) { const std::vector<std::string> &resultList) {
bool success = true; bool success = true;
for (size_t i = 0; i < inputList.size(); i++) { for (size_t i = 0; i < inputList.size(); i++) {
......
...@@ -270,23 +270,19 @@ public: ...@@ -270,23 +270,19 @@ public:
void test_joinCompress() { void test_joinCompress() {
std::vector<std::vector<int>> inputList{ std::vector<std::vector<int>> inputList{
{1,2,3}, {1, 2, 3},
{-1,0,1}, {-1, 0, 1},
{356,366,367,368,370,371,372,375}, {356, 366, 367, 368, 370, 371, 372, 375},
{7,6,5,6,7,8,10} {7, 6, 5, 6, 7, 8, 10}};
};
std::vector<std::string> resultList{ std::vector<std::string> resultList{
"1-3", "1-3", "-1-1", "356,366-368,370-372,375", "7,6,5-8,10"};
"-1-1",
"356,366-368,370-372,375",
"7,6,5-8,10"
};
for (size_t i = 0; i < inputList.size(); i++) { for (size_t i = 0; i < inputList.size(); i++) {
const auto& inputVector = inputList[i]; const auto &inputVector = inputList[i];
TS_ASSERT_EQUALS(joinCompress(inputVector.begin(), inputVector.end(),",","-"), resultList[i]); TS_ASSERT_EQUALS(
joinCompress(inputVector.begin(), inputVector.end(), ",", "-"),
resultList[i]);
} }
} }
void test_endsWithInt() { void test_endsWithInt() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment