//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include #include TTS_CASE_TPL("I/O for matrix", rotgen::tests::types)( tts::type>) { rotgen::matrix x( {{1, 2}, {3, 4}}); std::ostringstream os; os << x; TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); }; TTS_CASE_TPL("I/O for block", rotgen::tests::types)( tts::type>) { rotgen::matrix base( {{1, 2}, {3, 4}}); auto x = rotgen::extract(base, 0, 0, 2, 2); std::ostringstream os; os << x; TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); }; TTS_CASE_TPL("I/O for map test", rotgen::tests::types)( tts::type>) { using base = rotgen::matrix; T data[] = {1, 2, 3, 4}; rotgen::map x(data, 2, 2); std::ostringstream os; os << x; if constexpr (O::value) TTS_EQUAL(os.str(), std::string{"1 2\n3 4"}); else TTS_EQUAL(os.str(), std::string{"1 3\n2 4"}); }; TTS_CASE_TPL("I/O using format", rotgen::tests::types)( tts::type>) { rotgen::ioformat io(rotgen::StreamPrecision, 0, ", ", ";\n", "<", ">", "[", "]"); rotgen::matrix x( {{1, 2}, {3, 4}}); { std::ostringstream os; os << rotgen::format(x, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } rotgen::map> m{x.data()}; { std::ostringstream os; os << rotgen::format(m, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } auto b = rotgen::extract(x, 0, 0, 2, 2); { std::ostringstream os; os << rotgen::format(b, io); TTS_EQUAL(os.str(), std::string{"[<1, 2>;\n <3, 4>]"}); } auto printer = [&](rotgen::ref const> r) { std::ostringstream st; st << rotgen::format(r, io); return st.str(); }; TTS_EQUAL(printer(x), std::string{"[<1, 2>;\n <3, 4>]"}); TTS_EQUAL(printer(m), std::string{"[<1, 2>;\n <3, 4>]"}); TTS_EQUAL(printer(b), std::string{"[<1, 2>;\n <3, 4>]"}); };