1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2019 Joel Holdsworth <[email protected]>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10 #include <sstream>
11
12 #include "main.h"
13
14 template<typename Scalar>
15 struct check_ostream_impl
16 {
runcheck_ostream_impl17 static void run()
18 {
19 const Array<Scalar,1,1> array(123);
20 std::ostringstream ss;
21 ss << array;
22 VERIFY(ss.str() == "123");
23
24 check_ostream_impl< std::complex<Scalar> >::run();
25 };
26 };
27
28 template<>
29 struct check_ostream_impl<bool>
30 {
runcheck_ostream_impl31 static void run()
32 {
33 const Array<bool,1,2> array(1, 0);
34 std::ostringstream ss;
35 ss << array;
36 VERIFY(ss.str() == "1 0");
37 };
38 };
39
40 template<typename Scalar>
41 struct check_ostream_impl< std::complex<Scalar> >
42 {
runcheck_ostream_impl43 static void run()
44 {
45 const Array<std::complex<Scalar>,1,1> array(std::complex<Scalar>(12, 34));
46 std::ostringstream ss;
47 ss << array;
48 VERIFY(ss.str() == "(12,34)");
49 };
50 };
51
52 template<typename Scalar>
check_ostream()53 static void check_ostream()
54 {
55 check_ostream_impl<Scalar>::run();
56 }
57
EIGEN_DECLARE_TEST(rand)58 EIGEN_DECLARE_TEST(rand)
59 {
60 CALL_SUBTEST(check_ostream<bool>());
61 CALL_SUBTEST(check_ostream<float>());
62 CALL_SUBTEST(check_ostream<double>());
63 CALL_SUBTEST(check_ostream<Eigen::numext::int8_t>());
64 CALL_SUBTEST(check_ostream<Eigen::numext::uint8_t>());
65 CALL_SUBTEST(check_ostream<Eigen::numext::int16_t>());
66 CALL_SUBTEST(check_ostream<Eigen::numext::uint16_t>());
67 CALL_SUBTEST(check_ostream<Eigen::numext::int32_t>());
68 CALL_SUBTEST(check_ostream<Eigen::numext::uint32_t>());
69 CALL_SUBTEST(check_ostream<Eigen::numext::int64_t>());
70 CALL_SUBTEST(check_ostream<Eigen::numext::uint64_t>());
71 }
72