00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * guettler@informatik.uni-leipzig.de * 00007 * * 00008 * This program is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation; either version 2 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the * 00020 * Free Software Foundation, Inc., * 00021 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00022 *************************************************************************** 00023 * * 00024 * DESCRIPTION * 00025 * 00026 * UNIT TESTS for sparse matrices * 00027 * * 00028 * * 00029 * $Log: sparsematrix.tests.hpp,v $ 00030 * Revision 1.1 2009/08/03 08:35:20 guettler 00031 * first tests, to be tested 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