source/numeric/matrix_test.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2005 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 #include "numeric/matrix.hxx"
00029 #include <stdio.h>
00030 
00031 using namespace ::scsolver::numeric;
00032 
00033 void basicIO()
00034 {
00035     printf("Original empty matrix\n");
00036     Matrix mx(3, 3);
00037     mx.print();     // empty matrix
00038     printf("Simple assignment: (0, 0) = 4.54   (0, 2) = 12.55   (1, 1) = 1.2   (2, 1) = 35.4   (2, 2) = 5\n");
00039     mx(0, 0) = 4.54;
00040     mx(0, 2) = 12.55;
00041     mx(1, 1) = 1.2;
00042     mx(2, 1) = 35.4;
00043     mx(2, 2) = 5.0;
00044     mx.print();
00045 
00046     printf("Transposing matrix\n");
00047     mx.trans().print();
00048 
00049     // Automatic resizing.
00050     printf("Automatic resizing\n");
00051     mx.setResizable(true);
00052     mx(3, 10) = 100;
00053     mx.print();
00054     mx.setResizable(false);
00055 
00056     // Shrink the matrix.
00057     printf("Shrinking the matrix to 3 x 3\n");
00058     mx.resize(3, 3);
00059     mx.print();
00060 
00061     // Expanding the matrix
00062     printf("Expanding the matrix to 5 x 5\n");
00063     mx.resize(5, 5);
00064     mx.print();
00065 
00066     // Shrinking it again.
00067     printf("Shrinking it again\n");
00068     mx.resize(3, 3);
00069     mx.print();
00070 
00071     // Bad index
00072     mx.setResizable(false);
00073     try
00074     {
00075         printf("Bad index: (-1, 0) = 999\n");
00076         mx(-1, 0) = 999;
00077     }
00078     catch (const BadIndex&)
00079     {
00080         printf("BadIndex exception caught on assigning a new value.\n");
00081     }
00082     mx.print();
00083 
00084     try
00085     {
00086         printf("Bad index: (0, -1) = 999\n");
00087         mx(0, -1) = 999;
00088     }
00089     catch (const BadIndex&)
00090     {
00091         printf("BadIndex exception caught on assigning a new value.\n");
00092     }
00093     mx.print();
00094 
00095     try
00096     {
00097         printf("Bad index: r = (10, 10)\n");
00098         double r = mx(10, 10);
00099         r = 20.5;
00100     }
00101     catch (const BadIndex&)
00102     {
00103         printf("BadIndex exception caught on querying a value.\n");
00104     }
00105     mx.print();
00106     mx.setResizable(true);
00107 
00108     printf("3 x 3 identity matrix\n");
00109     Matrix mxi(3, 3, true);
00110     mxi.print();
00111 }
00112 
00113 int main()
00114 {
00115     printf("unit test: Matrix\n");
00116     basicIO();
00117     printf("Unit test passed!\n");
00118 }

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3