Back to index

salome-med  6.5.0
MEDMEMTest_SkyLineArray.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDMEMTest.hxx"
00021 #include <cppunit/TestAssert.h>
00022 #include "MEDMEM_SkyLineArray.hxx"
00023 #include "MEDMEM_define.hxx"
00024 
00025 #include <sstream>
00026 #include <cmath>
00027 
00028 using namespace std;
00029 using namespace MEDMEM;
00030 
00056 void MEDMEMTest::testSkyLineArray()
00057 {
00058   int NumberOfCell = 3 ; // 1 triangle,1 quadrangle,1 triangle
00059   int Size = 10 ; // 10 nodes
00060 
00061   int * index = new int[NumberOfCell+1] ;
00062   index[0]=1;
00063   index[1]=4;
00064   index[2]=8;
00065   index[3]=11;
00066   int * value = new int[Size] ;
00067   value[0]=1; // first
00068   value[1]=2;
00069   value[2]=5;
00070   value[3]=2; // second
00071   value[4]=3;
00072   value[5]=5;
00073   value[6]=6;
00074   value[7]=3; // thirst
00075   value[8]=4;
00076   value[9]=6;
00077   //  value[]=; // forth
00078 
00079   MEDSKYLINEARRAY * myArray = new MEDSKYLINEARRAY(NumberOfCell,Size,index,value) ;
00080   const int * ArrayIndex ;
00081   try
00082   {
00083     ArrayIndex = myArray->getIndex() ;
00084   }
00085   catch ( const std::exception &e )
00086   {
00087     CPPUNIT_FAIL(e.what());
00088   }
00089   catch (...)
00090   {
00091     CPPUNIT_FAIL("Unknown exception");
00092   }
00093 
00094   const int * ArrayValue ;
00095   try
00096   {
00097     ArrayValue  = myArray->getValue() ;
00098   }
00099   catch ( const std::exception &e )
00100   {
00101     CPPUNIT_FAIL(e.what());
00102   }
00103   catch (...)
00104   {
00105     CPPUNIT_FAIL("Unknown exception");
00106   }
00107 
00108 
00109   try
00110   {
00111     CPPUNIT_ASSERT(myArray->getNumberOf()==NumberOfCell);
00112 
00113   }
00114   catch ( const std::exception &e )
00115   {
00116     CPPUNIT_FAIL(e.what());
00117   }
00118   catch (...)
00119   {
00120     CPPUNIT_FAIL("Unknown exception");
00121   }
00122 
00123   try
00124   {
00125     CPPUNIT_ASSERT(myArray->getLength()==Size);
00126   }
00127   catch ( const std::exception &e )
00128   {
00129     CPPUNIT_FAIL(e.what());
00130   }
00131   catch (...)
00132   {
00133     CPPUNIT_FAIL("Unknown exception");
00134   }
00135 
00136   for (int i=1; i< NumberOfCell+1 ; i++) 
00137   {
00138     const int * cell;
00139     CPPUNIT_ASSERT_NO_THROW(cell = myArray->getI(i));
00140     int numberof;
00141     CPPUNIT_ASSERT_NO_THROW(numberof= myArray->getNumberOfI(i));
00142     CPPUNIT_ASSERT(numberof==index[i]-index[i-1]);
00143     int verif;
00144     for (int j=0;j<numberof;j++)
00145     {
00146       CPPUNIT_ASSERT_NO_THROW(verif=myArray->getIJ(i,j+1));
00147       CPPUNIT_ASSERT(verif == cell[j]);
00148     }
00149   }
00150 
00151   MEDSKYLINEARRAY * myArray2 = new MEDSKYLINEARRAY(*myArray) ;
00152   delete myArray ;
00153   
00154   const int * index2 = myArray2->getIndex() ;
00155   for (int i=1; i<=NumberOfCell ; i++) {
00156     for (int j=index2[i-1];j<index2[i];j++)
00157       CPPUNIT_ASSERT_NO_THROW(myArray2->getIndexValue(j));
00158   }
00159 
00160   delete myArray2 ;
00161 
00162   MEDSKYLINEARRAY myArray3(NumberOfCell,Size);
00163   try
00164   { 
00165     myArray3.setIndex(index);
00166   }
00167   catch ( const std::exception &e )
00168   {
00169     CPPUNIT_FAIL(e.what());
00170   }
00171   catch (...)
00172   {
00173     CPPUNIT_FAIL("Unknown exception");
00174   }
00175 
00176   CPPUNIT_ASSERT_THROW(myArray3.setI(0, 0),MEDEXCEPTION);
00177 
00178   for (int i=1; i<NumberOfCell+1 ; i++) {
00179     CPPUNIT_ASSERT_NO_THROW(myArray3.setI(i, &value[index[i-1]-1]));
00180   }
00181 
00182   for (int i=1; i<NumberOfCell+1 ; i++) {
00183     int numberof;
00184     CPPUNIT_ASSERT_NO_THROW(numberof = myArray3.getNumberOfI(i));
00185     for (int j=1;j<numberof+1;j++)
00186       CPPUNIT_ASSERT_NO_THROW(myArray3.setIJ(i,j,myArray3.getIJ(i,j))) ;
00187   }
00188   
00189   for (int i=1; i<=NumberOfCell ; i++) {
00190     for (int j=index[i-1];j<index[i];j++)
00191       CPPUNIT_ASSERT_NO_THROW(myArray3.setIndexValue(j,value[j-1]));
00192   }
00193 
00194   delete[] index ;
00195   delete[] value ;
00196   ostringstream out;
00197   MEDSKYLINEARRAY myEmptyArray;
00198   out<<myEmptyArray<<endl;
00199 }
00200