// test_Matrix.cpp (C) 2004 adolfo@di-mare.com /** \file test_Matrix.cpp \brief Este programita sirve para ver cómo funciona la matriz... \author Adolfo Di Mare \date 2004 - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04 */ #include // cout #include // setw(4) #include "Matrix_Lib.h" #include "Matrix_List.h" using namespace Mx; using namespace std; // declaración anticipada template int real_main(); /// Programa principal. int main() { return real_main< Matrix_List >(); } /// Imprime por filas el valor de \c "M" template void print( const char* name, MAT & V ) { cout << endl << name << '[' << V.rows() << ',' << V.cols() << ']' << endl; for (unsigned i=0; i < V.rows(); ++i) { for (unsigned j=0; j < V.cols(); ++j) { cout << " " << setw(6) << V(i,j); } cout << endl; } } /// Programa que ejercita las principales funciones de las matrices template int real_main() { const unsigned M = 5; const unsigned N = 8; unsigned i,j,k; MAT V(M,N); k = 0; for (i=0; i < V.rows(); ++i) { for (j=0; j < V.cols(); ++j) { V.at(i,j) = k++; // V.operator()(i,j) = k++; V.operator()(i,j) = V.at(i,j); } } assert( k == 5*8 && 40 == N*M ); MAT A = V; assert( A == V ); assert( A.same(A) ); print("A", A); V.reSize(N,M); print("V", V); // k = 0; for (i=0; i < V.rows(); ++i) { for (j=0; j < V.cols(); ++j) { V(i,j) = 0*V.at(i,j) + k; k++; } } MAT B; B = V; assert( B == V ); print("B", B); typedef MAT Matrix_rename; Matrix_rename C = V; C = C + C; print("C", C); C = A - A; print("C", C); assert( isNull( C ) && ! isScalar( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isSquare( C ) && ! isUnit( C ) ); assert( ! isSymmetric( C ) ); print("A", A); // B.transpose(); print("B", B); C = B * A; print("C", C); assert( ! isNull( C ) && isSquare( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isUnit( C ) && ! isScalar( C ) ); assert( ! isSymmetric( C ) ); print("A", A); print("B", B); C = A * B; print("C", C); assert( ! isNull( C ) && isSquare( C ) ); assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) ); assert( ! isUnit( C ) && ! isScalar( C ) ); assert( ! isSymmetric( C ) ); assert( C.at(4,4) == 17676 && 1820 == C.at(0,0) ); return 0; } // EOF: test_Matrix.cpp