//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #include "unit/tests.hpp" #include TTS_CASE_TPL("Default matrix dynamic constructor", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), rotgen::Index{0}); TTS_EQUAL(matrix.cols(), rotgen::Index{0}); }; TTS_CASE_TPL("Default matrix static constructor", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), rotgen::Index{4}); TTS_EQUAL(matrix.cols(), rotgen::Index{9}); }; TTS_CASE_TPL("Dynamic matrix constructor with row and columns", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix matrix(10, 5); TTS_EQUAL(matrix.rows(), rotgen::Index{10}); TTS_EQUAL(matrix.cols(), rotgen::Index{5}); }; TTS_CASE_TPL("Static matrix constructor with row and columns", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix matrix(6, 11); TTS_EQUAL(matrix.rows(), rotgen::Index{6}); TTS_EQUAL(matrix.cols(), rotgen::Index{11}); }; TTS_CASE_TPL("Copy constructor produces identical but independent matrix", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix a(3, 3); for(rotgen::Index r=0;r b = a; TTS_EQUAL(b.rows(), a.rows()); TTS_EQUAL(b.cols(), a.cols()); for(rotgen::Index r=0;r( tts::type< tts::types> ) { rotgen::matrix a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), rotgen::Index{0}); TTS_EQUAL(b.cols(), rotgen::Index{0}); }; TTS_CASE_TPL("Copy constructor from const matrix", rotgen::tests::types) ( tts::type< tts::types> ) { const rotgen::matrix a(2, 2); auto b = a; TTS_EQUAL(b.rows(), rotgen::Index{2}); TTS_EQUAL(b.cols(), rotgen::Index{2}); }; TTS_CASE_TPL("Copy constructor on static matrix", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), rotgen::Index{2}); TTS_EQUAL(b.cols(), rotgen::Index{5}); }; TTS_CASE_TPL("Copy constructor on static/dynamic matrix", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), 11); TTS_EQUAL(b.cols(), 4); }; TTS_CASE_TPL("Copy constructor on dynamic/static matrix", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix a(5, 7); rotgen::matrix b = a; TTS_EQUAL(b.rows(), 5); TTS_EQUAL(b.cols(), 7); }; TTS_CASE_TPL("Move constructor transfers contents", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix a(3, 3); a(1,1) = 7; auto ptr = a.data(); rotgen::matrix b = std::move(a); TTS_EQUAL(b(1,1), 7); TTS_EQUAL(b.rows(), rotgen::Index{3}); TTS_EQUAL(b.cols(), rotgen::Index{3}); TTS_EXPECT(b.data() == ptr); }; TTS_CASE_TPL("Move constructor from Rvalue", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix b = rotgen::matrix(2, 2); TTS_EQUAL(b.rows(), rotgen::Index{2}); TTS_EQUAL(b.cols(), rotgen::Index{2}); }; TTS_CASE_TPL("Constructor from Initializer list", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix b1{3.5}; TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1}); TTS_EQUAL(b1(0) , 3.5); rotgen::matrix b9{0.25, 0.5, 1, 2, 4}; TTS_EQUAL(b9.rows(), rotgen::Index{5}); TTS_EQUAL(b9.cols(), rotgen::Index{1}); T i = 0.25; for(rotgen::Index r=0;r b13{1.2,2.3,3.4}; TTS_EQUAL(b13.rows(), rotgen::Index{1}); TTS_EQUAL(b13.cols(), rotgen::Index{3}); TTS_EQUAL(b13(0) , T(1.2)); TTS_EQUAL(b13(1) , T(2.3)); TTS_EQUAL(b13(2) , T(3.4)); }; TTS_CASE_TPL("Constructor from Initializer list of rows", rotgen::tests::types) ( tts::type< tts::types> ) { rotgen::matrix b1{{3.5}}; TTS_EQUAL(b1.rows(), rotgen::Index{1}); TTS_EQUAL(b1.cols(), rotgen::Index{1}); TTS_EQUAL(b1(0,0) , T(3.5)); rotgen::matrix b23 { {1.2,2.3,3.4} , {10,200,3000} }; TTS_EQUAL(b23.rows(), rotgen::Index{2}); TTS_EQUAL(b23.cols(), rotgen::Index{3}); TTS_EQUAL(b23(0,0) , T(1.2)); TTS_EQUAL(b23(0,1) , T(2.3)); TTS_EQUAL(b23(0,2) , T(3.4)); TTS_EQUAL(b23(1,0) , T(10)); TTS_EQUAL(b23(1,1) , T(200)); TTS_EQUAL(b23(1,2) , T(3000)); };