86 lines
2.5 KiB
C++
86 lines
2.5 KiB
C++
//==================================================================================================
|
|
/*
|
|
ROTGEN - Runtime Overlay for Eigen
|
|
Copyright : CODE RECKONS
|
|
SPDX-License-Identifier: BSL-1.0
|
|
*/
|
|
//==================================================================================================
|
|
#include "unit/tests.hpp"
|
|
#include <rotgen/rotgen.hpp>
|
|
#include <sstream>
|
|
|
|
TTS_CASE_TPL("I/O for matrix", rotgen::tests::types)
|
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
|
{
|
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> 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)
|
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
|
{
|
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> 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)
|
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
|
{
|
|
using base = rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>;
|
|
|
|
T data[] = {1,2,3,4};
|
|
|
|
rotgen::map<base> 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)
|
|
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
|
{
|
|
rotgen::ioformat io(rotgen::StreamPrecision, 0, ", ", ";\n", "<", ">", "[", "]");
|
|
|
|
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> 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<rotgen::matrix<T,2,2,O::value>> 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 rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value>> 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>]"});
|
|
};
|