Robot Simulator of the Robotics Group for Self-Organization of Control: sparsematrix.tests.hpp Source File

# sparsematrix.tests.hpp

Go to the documentation of this file.

    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$
    00030  *  Revision 1.2  2011-11-11 15:43:06  martius
    00031  *  color schemas (palettes and aliases) supported
    00032  *  small compile error removed
    00033  *  DUNITTEST removed in selforg-config and oderobots-config
    00034  *
    00035  *  Revision 1.1  2009/08/03 08:35:20  guettler
    00036  *  first tests, to be tested
    00037  *                                           *
    00038  *                                                                         *
    00039  **************************************************************************/
    00040 #ifdef UNITTEST
    00041 #include "unit_test.hpp"
    00042 #include <string.h>
    00043 #include <cmath>
    00044 #include <algorithm>
    00045 using namespace matrix;
    00046
    00047
    00048 UNIT_TEST_DEFINES
    00049
    00050 DEFINE_TEST( check_creation ) {
    00051   std::cout << "\n -[ Creation and Access ]-\n";
    00052   SparseMatrix<int,double> M1(3,3);
    00053   double testdata[9]={1,0,0, 0,1,0, 0,0,1};
    00054   M1.set(testdata);
    00055   unit_assert( "identity_set=id",
    00056       M1[0] == 1 && M1[1] == 0 && M1[2] == 0 &&
    00057       M1[3] == 0 && M1[4] == 1 && M1[5] == 0 &&
    00058       M1[6] == 0 && M1[8] == 0 && M1[9] == 1);
    00059   double testdata2[12]={1,2,3, 4,5,6, 7,8,9, 10,11,12};
    00060   SparseMatrix<int,double> M3(4,3);
    00061   M3.set(testdata2);
    00062   unit_assert( "dimension of matrix", M3.getM() == 4 &&  M3.getN() == 3 );
    00063   unit_assert( "field check",
    00064                M3.val(0,2) == 3 &&  M3.val(2,1) == 8 &&  M3.val(3,0) == 10 );
    00065   unit_pass();
    00066 }
    00067
    00068
    00069 UNIT_TEST_RUN( "SparseMatrix Tests" )
    00070   ADD_TEST( check_creation )
    00071
    00072   UNIT_TEST_END
    00073
    00074 #endif // UNITTEST