11TEST(ostream_container, simple_vector_int)
13 std::vector<int> vi{2, 4, 6, 8};
14 std::ostringstream oss;
18 ASSERT_EQ(oss.str(), std::string(
"[2, 4, 6, 8]"));
23template <
typename Container>
35template <
typename Tests>
38 for (
auto &
test : tests)
40 std::ostringstream oss;
44 EXPECT_EQ(oss.str(),
test.expected);
48template <
template <
typename...>
typename Coll_T,
typename Val_T>
51 Coll_T<Val_T *> transformed;
52 typename Coll_T<Val_T>::const_iterator inIt = colln.begin(), inEndIt = colln.end();
54 std::transform(inIt, inEndIt, std::back_inserter(transformed), [](
const Val_T &in) -> Val_T *
55 {
return const_cast<Val_T *
>(&in); });
60template <
typename Tests>
63 for (
auto &
test : tests)
67 std::ostringstream oss;
71 EXPECT_EQ(oss.str(),
test.expected);
76using ssi = std::set<int>;
83TEST(ostream_container, set_int)
96using sls = std::list<std::string>;
98 TestItem<sls>({
"Alfred",
"E.",
"Neuman"},
"[Alfred, E., Neuman]"),
99 TestItem<sls>({
"Institute has",
"the finest",
"professors"},
"[Institute has, the finest, professors]"),
102TEST(ostream_container, list_string)
108using svc = std::vector<std::complex<double>>;
110 TestItem<svc>({{1.5, 2.0}, {6.4, 7.2}, {8.9, 0.4}},
"[(1.5,2), (6.4,7.2), (8.9,0.4)]"),
111 TestItem<svc>({{-5, 0}, {18, 500}, {1e6, 32}},
"[(-5,0), (18,500), (1e+06,32)]"),
114TEST(ostream_container, vector_complex)
123 : std::complex<double>(re, im)
130 os << mc.real() <<
"+i" << mc.imag();
134using sdm = std::deque<MyComplex>;
136 TestItem<sdm>({{1.5, 2.0}, {6.4, 7.2}, {8.9, 0.4}},
"[1.5+i2, 6.4+i7.2, 8.9+i0.4]"),
137 TestItem<sdm>({{-5, 0}, {18, 500}, {1e6, 32}},
"[-5+i0, 18+i500, 1e+06+i32]"),
140TEST(ostream_container, deque_custom)
const auto cast(const C &container)
Provide an instance of C2os::Container<C> from the underlying container.
const auto cast_deref(const C &container)
Provide an instance of C2os::PtrContainer<C> from the underlying container.
std::basic_ostream< Elem, Traits > & operator<<(std::basic_ostream< Elem, Traits > &os, const SafeString &ss)
Coercion safe method to insert a container into an ostream.
MyComplex(double re, double im)
TestItem(Container &&c, std::string &&s)
const std::string expected
const Container container
std::vector< std::complex< double > > svc
void generic_ptr_test(const Tests &tests)
std::deque< MyComplex > sdm
const TestItem< ssi > set_int_tests[]
const TestItem< svc > vector_complex_tests[]
const TestItem< sdm > deque_custom_tests[]
TEST(ostream_container, simple_vector_int)
const TestItem< sls > list_string_tests[]
auto container_of_pointers(const Coll_T< Val_T > &colln)
void generic_test(const Tests &tests)
std::list< std::string > sls