Abstract non Polymorphyc Matrix:
 All Classes Namespaces Files Functions Variables Typedefs Friends Defines
test_Matrix.cpp
Go to the documentation of this file.
00001 // test_Matrix.cpp  (C)  2004 adolfo@di-mare.com
00002 
00003 /** \file  test_Matrix.cpp
00004     \brief Este programita sirve para ver cómo funciona la matriz...
00005 
00006     \author Adolfo Di Mare <adolfo@di-mare.com>
00007     \date   2004
00008 
00009     - Why English names??? ==> http://www.di-mare.com/adolfo/binder/c01.htm#sc04
00010 */
00011 
00012 #include <iostream>  // cout
00013 #include <iomanip>   // setw(4)
00014 
00015 #include "Matrix_Lib.h"
00016 #include "Matrix_List.h"
00017 
00018 using namespace Mx;
00019 using namespace std;
00020 
00021 // declaración anticipada
00022 template <class MAT> int real_main();
00023 
00024 /// Programa principal.
00025 int main() {
00026     return real_main< Matrix_List<unsigned> >();
00027 }
00028 
00029 /// Imprime por filas el valor de \c "M"
00030 template <class MAT>
00031 void print( const char* name, MAT & V ) {
00032     cout << endl << name << '[' << V.rows() << ',' << V.cols() << ']' << endl;
00033     for (unsigned i=0; i < V.rows(); ++i) {
00034         for (unsigned j=0; j < V.cols(); ++j) {
00035             cout << " " << setw(6) << V(i,j);
00036         }
00037         cout << endl;
00038     }
00039 }
00040 
00041 /// Programa que ejercita las principales funciones de las matrices
00042 template <class MAT>
00043 int real_main() {
00044     const unsigned M = 5;
00045     const unsigned N = 8;
00046     unsigned i,j,k;
00047     MAT V(M,N);
00048 
00049     k = 0;
00050     for (i=0; i < V.rows(); ++i) {
00051         for (j=0; j < V.cols(); ++j) {
00052             V.at(i,j) = k++;        // V.operator()(i,j) = k++;
00053             V.operator()(i,j) = V.at(i,j);
00054         }
00055     }
00056     assert( k == 5*8 && 40 == N*M );
00057 
00058     MAT A = V;
00059     assert( A == V );
00060     assert( A.same(A) );
00061     print("A", A);
00062 
00063     V.reSize(N,M);
00064     print("V", V);
00065 
00066     // k = 0;
00067     for (i=0; i < V.rows(); ++i) {
00068         for (j=0; j < V.cols(); ++j) {
00069             V(i,j) = 0*V.at(i,j) + k;
00070             k++;
00071         }
00072     }
00073 
00074     MAT B;
00075     B = V;
00076     assert( B == V );
00077     print("B", B);
00078 
00079     typedef MAT Matrix_rename;
00080     Matrix_rename C = V;
00081     C = C + C;
00082     print("C", C);
00083 
00084     C = A - A;
00085     print("C", C);
00086     assert( isNull( C ) && ! isScalar( C ) );
00087     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00088     assert( ! isSquare( C ) &&  ! isUnit( C ) );
00089     assert( ! isSymmetric( C ) );
00090 
00091     print("A", A);
00092 //  B.transpose();
00093     print("B", B);
00094     C = B * A;
00095     print("C", C);
00096     assert( ! isNull( C ) && isSquare( C ) );
00097     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00098     assert( ! isUnit( C ) && ! isScalar( C ) );
00099     assert( ! isSymmetric( C ) );
00100 
00101     print("A", A);
00102     print("B", B);
00103     C = A * B;
00104     print("C", C);
00105     assert( ! isNull( C ) && isSquare( C ) );
00106     assert( ! isLowerTiangular( C ) && ! isUpperTiangular( C ) );
00107     assert( ! isUnit( C ) && ! isScalar( C ) );
00108     assert( ! isSymmetric( C ) );
00109     assert( C.at(4,4) == 17676 && 1820 == C.at(0,0) );
00110 
00111     return 0;
00112 }
00113 
00114 
00115 // EOF: test_Matrix.cpp