aboutsummaryrefslogtreecommitdiff
path: root/test/conservative_resize.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/conservative_resize.cpp')
-rw-r--r--test/conservative_resize.cpp66
1 files changed, 43 insertions, 23 deletions
diff --git a/test/conservative_resize.cpp b/test/conservative_resize.cpp
index 4d11e4075..498421b4c 100644
--- a/test/conservative_resize.cpp
+++ b/test/conservative_resize.cpp
@@ -60,34 +60,51 @@ void run_matrix_tests()
template <typename Scalar>
void run_vector_tests()
{
- typedef Matrix<Scalar, 1, Eigen::Dynamic> MatrixType;
+ typedef Matrix<Scalar, 1, Eigen::Dynamic> VectorType;
- MatrixType m, n;
+ VectorType m, n;
// boundary cases ...
- m = n = MatrixType::Random(50);
+ m = n = VectorType::Random(50);
m.conservativeResize(1);
VERIFY_IS_APPROX(m, n.segment(0,1));
- m = n = MatrixType::Random(50);
+ m = n = VectorType::Random(50);
m.conservativeResize(50);
VERIFY_IS_APPROX(m, n.segment(0,50));
+
+ m = n = VectorType::Random(50);
+ m.conservativeResize(m.rows(),1);
+ VERIFY_IS_APPROX(m, n.segment(0,1));
+
+ m = n = VectorType::Random(50);
+ m.conservativeResize(m.rows(),50);
+ VERIFY_IS_APPROX(m, n.segment(0,50));
// random shrinking ...
for (int i=0; i<50; ++i)
{
const int size = internal::random<int>(1,50);
- m = n = MatrixType::Random(50);
+ m = n = VectorType::Random(50);
m.conservativeResize(size);
VERIFY_IS_APPROX(m, n.segment(0,size));
+
+ m = n = VectorType::Random(50);
+ m.conservativeResize(m.rows(), size);
+ VERIFY_IS_APPROX(m, n.segment(0,size));
}
// random growing with zeroing ...
for (int i=0; i<50; ++i)
{
const int size = internal::random<int>(50,100);
- m = n = MatrixType::Random(50);
- m.conservativeResizeLike(MatrixType::Zero(size));
+ m = n = VectorType::Random(50);
+ m.conservativeResizeLike(VectorType::Zero(size));
+ VERIFY_IS_APPROX(m.segment(0,50), n);
+ VERIFY( size<=50 || m.segment(50,size-50).sum() == Scalar(0) );
+
+ m = n = VectorType::Random(50);
+ m.conservativeResizeLike(Matrix<Scalar,Dynamic,Dynamic>::Zero(1,size));
VERIFY_IS_APPROX(m.segment(0,50), n);
VERIFY( size<=50 || m.segment(50,size-50).sum() == Scalar(0) );
}
@@ -95,20 +112,23 @@ void run_vector_tests()
void test_conservative_resize()
{
- CALL_SUBTEST_1((run_matrix_tests<int, Eigen::RowMajor>()));
- CALL_SUBTEST_1((run_matrix_tests<int, Eigen::ColMajor>()));
- CALL_SUBTEST_2((run_matrix_tests<float, Eigen::RowMajor>()));
- CALL_SUBTEST_2((run_matrix_tests<float, Eigen::ColMajor>()));
- CALL_SUBTEST_3((run_matrix_tests<double, Eigen::RowMajor>()));
- CALL_SUBTEST_3((run_matrix_tests<double, Eigen::ColMajor>()));
- CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::RowMajor>()));
- CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::ColMajor>()));
- CALL_SUBTEST_5((run_matrix_tests<std::complex<double>, Eigen::RowMajor>()));
- CALL_SUBTEST_6((run_matrix_tests<std::complex<double>, Eigen::ColMajor>()));
-
- CALL_SUBTEST_1((run_vector_tests<int>()));
- CALL_SUBTEST_2((run_vector_tests<float>()));
- CALL_SUBTEST_3((run_vector_tests<double>()));
- CALL_SUBTEST_4((run_vector_tests<std::complex<float> >()));
- CALL_SUBTEST_5((run_vector_tests<std::complex<double> >()));
+ for(int i=0; i<g_repeat; ++i)
+ {
+ CALL_SUBTEST_1((run_matrix_tests<int, Eigen::RowMajor>()));
+ CALL_SUBTEST_1((run_matrix_tests<int, Eigen::ColMajor>()));
+ CALL_SUBTEST_2((run_matrix_tests<float, Eigen::RowMajor>()));
+ CALL_SUBTEST_2((run_matrix_tests<float, Eigen::ColMajor>()));
+ CALL_SUBTEST_3((run_matrix_tests<double, Eigen::RowMajor>()));
+ CALL_SUBTEST_3((run_matrix_tests<double, Eigen::ColMajor>()));
+ CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::RowMajor>()));
+ CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::ColMajor>()));
+ CALL_SUBTEST_5((run_matrix_tests<std::complex<double>, Eigen::RowMajor>()));
+ CALL_SUBTEST_6((run_matrix_tests<std::complex<double>, Eigen::ColMajor>()));
+
+ CALL_SUBTEST_1((run_vector_tests<int>()));
+ CALL_SUBTEST_2((run_vector_tests<float>()));
+ CALL_SUBTEST_3((run_vector_tests<double>()));
+ CALL_SUBTEST_4((run_vector_tests<std::complex<float> >()));
+ CALL_SUBTEST_5((run_vector_tests<std::complex<double> >()));
+ }
}