sparsematrix.tests.hpp
Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035 #ifdef UNITTEST
00036 #include "unit_test.hpp"
00037 #include <string.h>
00038 #include <cmath>
00039 #include <algorithm>
00040 using namespace matrix;
00041
00042
00043 UNIT_TEST_DEFINES
00044
00045 DEFINE_TEST( check_creation ) {
00046 std::cout << "\n -[ Creation and Access ]-\n";
00047 SparseMatrix<double> M1(3,3);
00048 double testdata[9]={1,0,0, 0,1,0, 0,0,1};
00049 M1.set(testdata);
00050 unit_assert( "identity_set=id",
00051 M1[0] == 1 && M1[1] == 0 && M1[2] == 0 &&
00052 M1[3] == 0 && M1[4] == 1 && M1[5] == 0 &&
00053 M1[6] == 0 && M1[8] == 0 && M1[9] == 1);
00054 double testdata2[12]={1,2,3, 4,5,6, 7,8,9, 10,11,12};
00055 SparseMatrix<double> M3(4,3);
00056 M3.set(testdata2);
00057 unit_assert( "dimension of matrix", M3.getM() == 4 && M3.getN() == 3 );
00058 unit_assert( "field check",
00059 M3.val(0,2) == 3 && M3.val(2,1) == 8 && M3.val(3,0) == 10 );
00060 unit_pass();
00061 }
00062
00063
00064 UNIT_TEST_RUN( "SparseMatrix Tests" )
00065 ADD_TEST( check_creation )
00066
00067 UNIT_TEST_END
00068
00069 #endif // UNITTEST