Skip to content
Snippets Groups Projects
Commit ce55f593 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

rm unused Base::algo::concat

parent f9fae54d
No related branches found
No related tags found
1 merge request!1638rename BaseUtil -> Base, and minor cleanup
......@@ -34,22 +34,6 @@ inline bool almostEqual(double a, double b, int ulp)
return std::abs(a - b) <= eps * ulp * (std::abs(a) + std::abs(b)) / 2;
}
//! Returns the concatenation of two std::vector%s.
template <class T>
std::vector<T> concat(const std::vector<T>& v1, const std::vector<T>& v2);
} // namespace Base::algo
// ************************************************************************************************
// Implementation
// ************************************************************************************************
template <class T>
std::vector<T> Base::algo::concat(const std::vector<T>& v1, const std::vector<T>& v2)
{
std::vector<T> v = v1;
v.insert(v.end(), v2.begin(), v2.end());
return v;
}
#endif // BORNAGAIN_BASE_UTIL_ALGORITHMS_H
#include "Base/Util/Algorithms.h"
#include "Tests/GTestWrapper/google_test.h"
#include <string>
#include <vector>
TEST(ConcatTest, SimpleType)
{
std::vector<int> A{1, 2, 3};
std::vector<int> B{4, 5};
std::vector<int> N;
EXPECT_EQ(Base::algo::concat(A, B), (std::vector<int>{1, 2, 3, 4, 5}));
EXPECT_EQ(Base::algo::concat(A, A), (std::vector<int>{1, 2, 3, 1, 2, 3}));
EXPECT_EQ(Base::algo::concat(A, N), A);
EXPECT_EQ(Base::algo::concat(N, B), B);
}
TEST(ConcatTest, Struct)
{
struct S {
std::string nam;
double val;
bool operator==(const S& o) const { return nam == o.nam && val == o.val; }
};
using V = std::vector<S>;
V A{{"a", 11.}};
V B{{"b", 2.}, {"c", .3}};
V N;
EXPECT_EQ(Base::algo::concat(A, B), (V{{"a", 11.}, {"b", 2.}, {"c", .3}}));
EXPECT_EQ(Base::algo::concat(A, A), (V{{"a", 11.}, {"a", 11.}}));
EXPECT_EQ(Base::algo::concat(A, N), A);
EXPECT_EQ(Base::algo::concat(N, B), B);
}
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