//================================================================================================== /* ROTGEN - Runtime Overlay for Eigen Copyright : CODE RECKONS SPDX-License-Identifier: BSL-1.0 */ //================================================================================================== #define TTS_MAIN #include #include "tts.hpp" TTS_CASE("Default matrix dynamic constructor") { rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), 0ULL); TTS_EQUAL(matrix.cols(), 0ULL); }; TTS_CASE("Default matrix static constructor") { rotgen::matrix matrix; TTS_EQUAL(matrix.rows(), 4ULL); TTS_EQUAL(matrix.cols(), 9ULL); }; TTS_CASE("Dynamic matrix constructor with row and columns") { rotgen::matrix matrix(10, 5); TTS_EQUAL(matrix.rows(), 10ULL); TTS_EQUAL(matrix.cols(), 5ULL); }; TTS_CASE("Static matrix constructor with row and columns") { rotgen::matrix matrix(6, 11); TTS_EQUAL(matrix.rows(), 6ULL); TTS_EQUAL(matrix.cols(), 11ULL); }; TTS_CASE("Copy constructor produces identical but independent matrix") { rotgen::matrix a(3, 3); for(std::size_t r=0;r b = a; TTS_EQUAL(b.rows(), a.rows()); TTS_EQUAL(b.cols(), a.cols()); for(std::size_t r=0;r a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), 0ULL); TTS_EQUAL(b.cols(), 0ULL); }; TTS_CASE("Copy constructor from const matrix") { const rotgen::matrix a(2, 2); auto b = a; TTS_EQUAL(b.rows(), 2ULL); TTS_EQUAL(b.cols(), 2ULL); }; TTS_CASE("Copy constructor on static matrix") { rotgen::matrix a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), 2ULL); TTS_EQUAL(b.cols(), 5ULL); }; /* TTS_CASE("Copy constructor on static/dynamic matrix") { rotgen::matrix a; rotgen::matrix b = a; TTS_EQUAL(b.rows(), 11); TTS_EQUAL(b.cols(), 4); }; TTS_CASE("Copy constructor on dynamic/static matrix") { rotgen::matrix a(5, 7); rotgen::matrix b = a; TTS_EQUAL(b.rows(), 5); TTS_EQUAL(b.cols(), 7); };*/ TTS_CASE("Move constructor transfers contents") { 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(), 3ULL); TTS_EQUAL(b.cols(), 3ULL); TTS_EXPECT(b.data() == ptr); // TTS_EXPECT(a.data() == nullptr); }; TTS_CASE("Move constructor from Rvalue") { rotgen::matrix b = rotgen::matrix(2, 2); TTS_EQUAL(b.rows(), 2ULL); TTS_EQUAL(b.cols(), 2ULL); }; TTS_CASE("Constructor from Initializer list") { rotgen::matrix b1 = {3.5}; TTS_EQUAL(b1.rows(), 1ULL); TTS_EQUAL(b1.cols(), 1ULL); TTS_EQUAL(b1(0) , 3.5); rotgen::matrix b9 = {0.01, 0.1, 1, 10, 100}; TTS_EQUAL(b9.rows(), 5ULL); TTS_EQUAL(b9.cols(), 1ULL); double i = 0.01; for(std::size_t r=0;r b13 = {1.2,2.3,3.4}; TTS_EQUAL(b13.rows(), 1ULL); TTS_EQUAL(b13.cols(), 3ULL); TTS_EQUAL(b13(0) , 1.2); TTS_EQUAL(b13(1) , 2.3); TTS_EQUAL(b13(2) , 3.4); }; TTS_CASE("Constructor from Initializer list of rows") { rotgen::matrix b1 = {{3.5}}; TTS_EQUAL(b1.rows(), 1ULL); TTS_EQUAL(b1.cols(), 1ULL); TTS_EQUAL(b1(0,0) , 3.5); rotgen::matrix b23 = { {1.2,2.3,3.4} , {10,200,3000} }; TTS_EQUAL(b23.rows(), 2ULL); TTS_EQUAL(b23.cols(), 3ULL); TTS_EQUAL(b23(0,0) , 1.2); TTS_EQUAL(b23(0,1) , 2.3); TTS_EQUAL(b23(0,2) , 3.4); TTS_EQUAL(b23(1,0) , 10); TTS_EQUAL(b23(1,1) , 200); TTS_EQUAL(b23(1,2) , 3000); };