00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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();
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
00050 printf("Automatic resizing\n");
00051 mx.setResizable(true);
00052 mx(3, 10) = 100;
00053 mx.print();
00054 mx.setResizable(false);
00055
00056
00057 printf("Shrinking the matrix to 3 x 3\n");
00058 mx.resize(3, 3);
00059 mx.print();
00060
00061
00062 printf("Expanding the matrix to 5 x 5\n");
00063 mx.resize(5, 5);
00064 mx.print();
00065
00066
00067 printf("Shrinking it again\n");
00068 mx.resize(3, 3);
00069 mx.print();
00070
00071
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 }