Medusa  1.1
Coordinate Free Mehless Method implementation
test/utils/stdtypesutils_test.cpp
#include "gtest/gtest.h"
namespace mm {
TEST(Utils, StdTypesSort) {
std::vector<int> a = {3, 1, 2};
std::vector<int> b = sorted(a);
EXPECT_EQ(3, a[0]);
EXPECT_EQ(1, a[1]);
EXPECT_EQ(2, a[2]);
EXPECT_EQ(1, b[0]);
EXPECT_EQ(2, b[1]);
EXPECT_EQ(3, b[2]);
sort(a);
EXPECT_EQ(b, a);
b = sorted(a, [](int i, int j) { return j < i; });
EXPECT_EQ(1, a[0]);
EXPECT_EQ(2, a[1]);
EXPECT_EQ(3, a[2]);
EXPECT_EQ(3, b[0]);
EXPECT_EQ(2, b[1]);
EXPECT_EQ(1, b[2]);
sort(a, [](int i, int j) { return j < i; });
EXPECT_EQ(b, a);
}
TEST(Utils, StdTypesPad) {
std::vector<std::vector<int>> a = {{2, 1}, {4}, {}, {1, 2, 3}};
std::vector<std::vector<int>> expected = {{2, 1, -1}, {4, -1, -1}, {-1, -1, -1}, {1, 2, 3}};
EXPECT_EQ(expected, pad(a, -1));
a = {{1, 2}, {3, 4}, {5, 6}};
EXPECT_EQ(a, pad(a, -1));
}
TEST(Utils, StdTypesTextSplit) {
EXPECT_EQ(std::vector<std::string>({"a", "b", "c"}), split("a,b,c", ','));
EXPECT_EQ(std::vector<std::string>({"a", "b", "c"}), split("a, b, c", ", "));
EXPECT_EQ(std::vector<std::string>({"", "", "", " ", ""}), split("aaa a", "a"));
EXPECT_EQ(std::vector<std::string>({"a", "b", ""}), split("a,b,", ","));
EXPECT_EQ(std::vector<std::string>({"a", "b", ""}), split("a,,b,,", ",,"));
}
TEST(Utils, StdTypesTextJoin) {
EXPECT_EQ("ababa", join({"a", "a", "a"}, 'b'));
EXPECT_EQ("ababa", join({"a", "a", "a"}, "b"));
EXPECT_EQ("abxabxa", join({"a", "a", "a"}, "bx"));
EXPECT_EQ("aa", join({"a", "", "a"}, ""));
EXPECT_EQ("a123123123123a123", join({"a", "", "", "", "a", ""}, "123"));
}
TEST(Utils, PrintTuple) {
std::stringstream ss;
std::tuple<int, double, std::string> t(2, 4.5, "asdf");
ss << t;
EXPECT_EQ("(2, 4.5, asdf)", ss.str());
ss.str({});
ss.clear();
std::tuple<> empty;
ss << empty;
EXPECT_EQ("()", ss.str());
}
} // namespace mm
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::join
std::string join(const std::vector< std::string > &parts, const std::string &joiner)
Joins a vector of strings back together.
stdtypesutils.hpp
mm::sorted
container_t sorted(container_t v)
Returns a sorted copy of container.
Definition: stdtypesutils.hpp:57
mm::sort
container_t & sort(container_t &v)
Sorts a container inplace.
Definition: stdtypesutils.hpp:43
mm::pad
container_t pad(container_t container, T value)
Pads a ragged array with given value.
Definition: stdtypesutils.hpp:78
mm::split
std::vector< std::string > split(const std::string &s, const std::string &delim)
Splits string by delim, returning a vector of tokens (including empty).
Definition: stdtypesutils.cpp:10