Implement fixed size options for rotgen containers
See merge request oss/rotgen!11
This commit is contained in:
parent
8e545dd51a
commit
2084874b1b
39 changed files with 1247 additions and 323 deletions
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
//==================================================================================================
|
||||
#include "unit/tests.hpp"
|
||||
#include <rotgen/matrix.hpp>
|
||||
#include <rotgen/rotgen.hpp>
|
||||
|
||||
TTS_CASE_TPL("Function size", rotgen::tests::types)
|
||||
<typename T, typename O>( tts::type< tts::types<T,O>> )
|
||||
|
|
@ -16,10 +16,10 @@ TTS_CASE_TPL("Function size", rotgen::tests::types)
|
|||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> row_vector(9,1);
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> column_vector(1,5);
|
||||
|
||||
TTS_EQUAL(empty_matrix.size(), 0ULL);
|
||||
TTS_EQUAL(matrix.size(), 12ULL);
|
||||
TTS_EQUAL(row_vector.size(), 9ULL);
|
||||
TTS_EQUAL(column_vector.size(), 5ULL);
|
||||
TTS_EQUAL(empty_matrix.size(), rotgen::Index{0});
|
||||
TTS_EQUAL(matrix.size(), rotgen::Index{12});
|
||||
TTS_EQUAL(row_vector.size(), rotgen::Index{9});
|
||||
TTS_EQUAL(column_vector.size(), rotgen::Index{5});
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
|
||||
|
|
@ -27,21 +27,21 @@ TTS_CASE_TPL("Resizing dynamic matrix", rotgen::tests::types)
|
|||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
|
||||
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r,c) = 42 + 2*c + r;
|
||||
|
||||
a.resize(3, 2);
|
||||
TTS_EQUAL(a.rows(), 3ULL);
|
||||
TTS_EQUAL(a.cols(), 2ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
TTS_GREATER(a(r,c),0);
|
||||
|
||||
a.resize(2,2);
|
||||
TTS_EQUAL(a.rows(), 2ULL);
|
||||
TTS_EQUAL(a.cols(), 2ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Resizing static matrix", rotgen::tests::types)
|
||||
|
|
@ -57,52 +57,52 @@ TTS_CASE_TPL("Dynamix matrix conservative resizing", rotgen::tests::types)
|
|||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(2, 3);
|
||||
|
||||
int i = 1;
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = i++;
|
||||
|
||||
a.conservativeResize(2, 3);
|
||||
TTS_EQUAL(a.rows(), 2ULL);
|
||||
TTS_EQUAL(a.cols(), 3ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(3));
|
||||
|
||||
i = 1;
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
TTS_EQUAL(a(r,c),i++);
|
||||
|
||||
a.conservativeResize(3, 2);
|
||||
TTS_EQUAL(a.rows(), 3ULL);
|
||||
TTS_EQUAL(a.cols(), 2ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
int expected[3][2] = { {1, 2}, {4, 5} };
|
||||
for(std::size_t r = 0; r < 2; ++r)
|
||||
for(std::size_t c = 0; c < 2; ++c)
|
||||
for(rotgen::Index r = 0; r < 2; ++r)
|
||||
for(rotgen::Index c = 0; c < 2; ++c)
|
||||
TTS_EQUAL(a(r, c), expected[r][c]);
|
||||
|
||||
a.conservativeResize(4, 4);
|
||||
TTS_EQUAL(a.rows(), 4ULL);
|
||||
TTS_EQUAL(a.cols(), 4ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(4));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(4));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(3,3), 0);
|
||||
|
||||
a.conservativeResize(2, 2);
|
||||
TTS_EQUAL(a.rows(), 2ULL);
|
||||
TTS_EQUAL(a.cols(), 2ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(2));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(1,1), 5);
|
||||
|
||||
a.conservativeResize(1, 2);
|
||||
TTS_EQUAL(a.rows(), 1ULL);
|
||||
TTS_EQUAL(a.cols(), 2ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(1));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(2));
|
||||
TTS_EQUAL(a(0,0), 1);
|
||||
TTS_EQUAL(a(0,1), 2);
|
||||
|
||||
a.conservativeResize(0, 0);
|
||||
TTS_EQUAL(a.rows(), 0ULL);
|
||||
TTS_EQUAL(a.cols(), 0ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(0));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(0));
|
||||
|
||||
a.conservativeResize(3, 3);
|
||||
TTS_EQUAL(a.rows(), 3ULL);
|
||||
TTS_EQUAL(a.cols(), 3ULL);
|
||||
TTS_EQUAL(a.rows(), rotgen::Index(3));
|
||||
TTS_EQUAL(a.cols(), rotgen::Index(3));
|
||||
};
|
||||
|
||||
TTS_CASE_TPL("Static matrix conservative resizing", rotgen::tests::types)
|
||||
|
|
@ -117,8 +117,8 @@ TTS_CASE_TPL("Test coefficient accessors", rotgen::tests::types)
|
|||
{
|
||||
rotgen::matrix<T,rotgen::Dynamic,rotgen::Dynamic,O::value> a(3, 5);
|
||||
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = r + 2 * c + 3;
|
||||
|
||||
TTS_EQUAL(a(0,0), 3);
|
||||
|
|
@ -143,19 +143,19 @@ TTS_CASE_TPL("Test one index coefficient accessors", rotgen::tests::types)
|
|||
int i = 1;
|
||||
if constexpr(!O::value)
|
||||
{
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
a(r, c) = i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(std::size_t r=0;r<a.rows();++r)
|
||||
for(std::size_t c=0;c<a.cols();++c)
|
||||
for(rotgen::Index r=0;r<a.rows();++r)
|
||||
for(rotgen::Index c=0;c<a.cols();++c)
|
||||
a(r, c) = i++;
|
||||
}
|
||||
|
||||
i = 1;
|
||||
for(std::size_t r=0;r<a.rows()*a.cols();++r)
|
||||
for(rotgen::Index r=0;r<a.rows()*a.cols();++r)
|
||||
TTS_EQUAL(a(r), i++) << a;
|
||||
|
||||
T& ref = a(2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue