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 #ifndef WMATRIX_TEST_H
00026 #define WMATRIX_TEST_H
00027
00028 #include <cxxtest/TestSuite.h>
00029
00030 #include "../WMatrix.h"
00031
00032
00033
00034
00035 class WMatrixTest : public CxxTest::TestSuite
00036 {
00037 public:
00038
00039
00040
00041 void testInstantiation( void )
00042 {
00043 TS_ASSERT_THROWS_NOTHING( WMatrix< double > matrix( 3, 2 ) );
00044 TS_ASSERT_THROWS_NOTHING( WMatrix< float > matrix( 3, 2 ) );
00045 }
00046
00047
00048
00049
00050 void testCopyInstantiation( void )
00051 {
00052 WMatrix< double > matrix( 3, 2 );
00053 TS_ASSERT_THROWS_NOTHING( WMatrix< double > matrix2( matrix ) );
00054 }
00055
00056
00057
00058
00059 void testGetNbRowsAndCols( void )
00060 {
00061 const size_t nbRows = 3, nbCols = 2;
00062 WMatrix< double > matrix( nbRows, nbCols );
00063 TS_ASSERT_EQUALS( matrix.getNbRows(), nbRows );
00064 TS_ASSERT_EQUALS( matrix.getNbCols(), nbCols );
00065 }
00066
00067
00068
00069
00070 void testElementAccessOperator( void )
00071 {
00072 const size_t nbRows = 3, nbCols = 2;
00073 WMatrix< double > matrix( nbRows, nbCols );
00074 TS_ASSERT_EQUALS( matrix( 0 , 0 ), 0. );
00075 TS_ASSERT_EQUALS( matrix( 0 , 1 ), 0. );
00076 TS_ASSERT_EQUALS( matrix( 1 , 0 ), 0. );
00077 TS_ASSERT_EQUALS( matrix( 1 , 1 ), 0. );
00078 TS_ASSERT_EQUALS( matrix( 2 , 0 ), 0. );
00079 TS_ASSERT_EQUALS( matrix( 2 , 1 ), 0. );
00080
00081 const double a = 3.14;
00082 matrix( 2, 1 ) = a;
00083 TS_ASSERT_EQUALS( matrix( 2, 1 ), a );
00084 }
00085
00086
00087
00088
00089 void testConstElementAccessOperator( void )
00090 {
00091 const size_t nbRows = 3, nbCols = 2;
00092 const WMatrix< double > matrix( nbRows, nbCols );
00093 TS_ASSERT_EQUALS( matrix( 0 , 0 ), 0. );
00094 TS_ASSERT_EQUALS( matrix( 0 , 1 ), 0. );
00095 TS_ASSERT_EQUALS( matrix( 1 , 0 ), 0. );
00096 TS_ASSERT_EQUALS( matrix( 1 , 1 ), 0. );
00097 TS_ASSERT_EQUALS( matrix( 2 , 0 ), 0. );
00098 TS_ASSERT_EQUALS( matrix( 2 , 1 ), 0. );
00099 }
00100
00101
00102
00103
00104 void testEqualityOperator( void )
00105 {
00106 const size_t nbRows = 3, nbCols = 2;
00107 const double a = 1.2, b = 2.3, c = 3.4, d = 4.5, e = 5.6, f = 6.7;
00108 WMatrix< double > matrix1( nbRows, nbCols );
00109 WMatrix< double > matrix2( nbRows, nbCols );
00110 WMatrix< double > matrix3( nbCols, nbRows );
00111
00112 matrix1( 0, 0 ) = a;
00113 matrix1( 0, 1 ) = b;
00114 matrix1( 1, 0 ) = c;
00115 matrix1( 1, 1 ) = d;
00116 matrix1( 2, 0 ) = e;
00117 matrix1( 2, 1 ) = f;
00118
00119 matrix2( 0, 0 ) = a;
00120 matrix2( 0, 1 ) = b;
00121 matrix2( 1, 0 ) = c;
00122 matrix2( 1, 1 ) = d;
00123 matrix2( 2, 0 ) = e;
00124 matrix2( 2, 1 ) = f;
00125
00126 matrix3( 0, 0 ) = a;
00127 matrix3( 0, 1 ) = b;
00128 matrix3( 0, 2 ) = c;
00129 matrix3( 1, 0 ) = d;
00130 matrix3( 1, 1 ) = e;
00131 matrix3( 1, 2 ) = f;
00132
00133 TS_ASSERT_EQUALS( matrix1 == matrix2, true );
00134 TS_ASSERT_EQUALS( matrix1 == matrix3, false );
00135
00136 matrix2( 0, 0 ) += 1.;
00137
00138 TS_ASSERT_EQUALS( matrix1 == matrix2, false );
00139 }
00140
00141
00142
00143
00144 void testInequalityOperator( void )
00145 {
00146 const size_t nbRows = 3, nbCols = 2;
00147 const double a = 1.2, b = 2.3, c = 3.4, d = 4.5, e = 5.6, f = 6.7;
00148 WMatrix< double > matrix1( nbRows, nbCols );
00149 WMatrix< double > matrix2( nbRows, nbCols );
00150 WMatrix< double > matrix3( nbCols, nbRows );
00151
00152 matrix1( 0, 0 ) = a;
00153 matrix1( 0, 1 ) = b;
00154 matrix1( 1, 0 ) = c;
00155 matrix1( 1, 1 ) = d;
00156 matrix1( 2, 0 ) = e;
00157 matrix1( 2, 1 ) = f;
00158
00159 matrix2( 0, 0 ) = a;
00160 matrix2( 0, 1 ) = b;
00161 matrix2( 1, 0 ) = c;
00162 matrix2( 1, 1 ) = d;
00163 matrix2( 2, 0 ) = e;
00164 matrix2( 2, 1 ) = f;
00165
00166 matrix3( 0, 0 ) = a;
00167 matrix3( 0, 1 ) = b;
00168 matrix3( 0, 2 ) = c;
00169 matrix3( 1, 0 ) = d;
00170 matrix3( 1, 1 ) = e;
00171 matrix3( 1, 2 ) = f;
00172
00173 TS_ASSERT_EQUALS( matrix1 != matrix2, false );
00174 TS_ASSERT_EQUALS( matrix1 != matrix3, true );
00175
00176 matrix2( 0, 0 ) += 1.;
00177
00178 TS_ASSERT_EQUALS( matrix1 != matrix2, true );
00179 }
00180
00181
00182
00183
00184 void testAssignmentOperator( void )
00185 {
00186 const size_t nbRows = 3, nbCols = 2;
00187 const double a = 1.2, b = 2.3, c = 3.4, d = 4.5, e = 5.6, f = 6.7;
00188 WMatrix< double > matrix1( nbRows, nbCols );
00189 WMatrix< double > matrix2( nbRows, nbCols );
00190
00191 matrix1( 0, 0 ) = a;
00192 matrix1( 0, 1 ) = b;
00193 matrix1( 1, 0 ) = c;
00194 matrix1( 1, 1 ) = d;
00195 matrix1( 2, 0 ) = e;
00196 matrix1( 2, 1 ) = f;
00197
00198 matrix2( 0, 0 ) = a + 1.;
00199 matrix2( 0, 1 ) = b + 2.;
00200 matrix2( 1, 0 ) = c + 3.;
00201 matrix2( 1, 1 ) = d + 4.;
00202 matrix2( 2, 0 ) = e + 5.;
00203 matrix2( 2, 1 ) = f + 6.;
00204
00205
00206 TS_ASSERT_EQUALS( matrix1 == matrix2, false );
00207
00208
00209 matrix1 = matrix2;
00210 TS_ASSERT_EQUALS( matrix1 == matrix2, true );
00211
00212 WMatrix< double > matrix3( nbRows, nbCols );
00213 WMatrix< double > matrix4( nbRows, nbCols );
00214
00215
00216 TS_ASSERT_EQUALS( matrix2 == matrix3, false );
00217 TS_ASSERT_EQUALS( matrix2 == matrix4, false );
00218
00219
00220
00221 matrix4 = matrix3 = matrix2;
00222 TS_ASSERT_EQUALS( matrix2 == matrix3, true );
00223 TS_ASSERT_EQUALS( matrix2 == matrix4, true );
00224 TS_ASSERT_EQUALS( matrix3 == matrix4, true );
00225 }
00226
00227
00228
00229
00230 void testTransposed( void )
00231 {
00232 const size_t nbRows = 3, nbCols = 2;
00233 WMatrix< int > matrix( nbRows, nbCols );
00234
00235 for( size_t row = 0; row < nbRows; row++ )
00236 for( size_t col = 0; col < nbCols; col++ )
00237 matrix( row, col ) = ( row+1 )*10 + col+1;
00238
00239 WMatrix< int > matrixTransposed( matrix.transposed() );
00240
00241
00242 TS_ASSERT_EQUALS( matrixTransposed.getNbCols(), matrix.getNbRows() );
00243 TS_ASSERT_EQUALS( matrixTransposed.getNbRows(), matrix.getNbCols() );
00244
00245
00246 for( size_t row = 0; row < nbRows; row++ )
00247 for( size_t col = 0; col < nbCols; col++ )
00248 TS_ASSERT_EQUALS( matrixTransposed( col, row ), ( row+1 )*10 + col + 1 );
00249 }
00250 };
00251
00252 #endif // WMATRIX_TEST_H