add unit tests

This commit is contained in:
Gael Guennebaud 2018-10-03 11:56:27 +02:00
parent 5f26f57598
commit 8a1e98240e

View File

@ -30,6 +30,7 @@ void test_range_for_loop(int rows=Rows, int cols=Cols)
using std::end;
typedef Matrix<Scalar,Rows,1> VectorType;
typedef Matrix<Scalar,1,Cols> RowVectorType;
typedef Matrix<Scalar,Rows,Cols,ColMajor> ColMatrixType;
typedef Matrix<Scalar,Rows,Cols,RowMajor> RowMatrixType;
VectorType v = VectorType::Random(rows);
@ -62,6 +63,9 @@ void test_range_for_loop(int rows=Rows, int cols=Cols)
VERIFY( is_PointerBasedStlIterator(cA.reshaped().begin()) );
VERIFY( is_PointerBasedStlIterator(cA.reshaped().end()) );
VERIFY( is_PointerBasedStlIterator(B.template reshaped<AutoOrder>().begin()) );
VERIFY( is_PointerBasedStlIterator(B.template reshaped<AutoOrder>().end()) );
VERIFY( is_DenseStlIterator(A.template reshaped<RowMajor>().begin()) );
VERIFY( is_DenseStlIterator(A.template reshaped<RowMajor>().end()) );
@ -252,6 +256,17 @@ void test_range_for_loop(int rows=Rows, int cols=Cols)
i = 0;
for(auto r : B.allRows()) { VERIFY_IS_APPROX(r.sum(), B.row(i).sum()); ++i; }
{
RowVectorType row = RowVectorType::Random(cols);
A.rowwise() = row;
VERIFY( std::all_of(A.allRows().begin(), A.allRows().end(), [&row](typename ColMatrixType::RowXpr x) { return internal::isApprox(x.norm(),row.norm()); }) );
VectorType col = VectorType::Random(rows);
A.colwise() = col;
VERIFY( std::all_of(A.allCols().begin(), A.allCols().end(), [&col](typename ColMatrixType::ColXpr x) { return internal::isApprox(x.norm(),col.norm()); }) );
}
#endif
}