Back to index

salome-med  6.5.0
testUSkyLineArray.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 //  File   : testUSkyLineArray.cxx
00021 //  Module : MED
00022 //
00023 #include <cstdlib>
00024 #include "MEDMEM_Utilities.hxx"
00025 #include "MEDMEM_SkyLineArray.hxx"
00026 
00027 using namespace std;
00028 using namespace MEDMEM;
00029 
00030 int main (int argc, char ** argv)
00031 {
00032 
00033   int NumberOfCell = 3 ; // 1 triangle,1 quadrangle,1 triangle
00034   int Size = 10 ;        // 10 nodes
00035 
00036   int * index = new int[NumberOfCell+1];
00037   index[0]=1;
00038   index[1]=4;
00039   index[2]=8;
00040   index[3]=11;
00041 
00042   int * value = new int[Size];
00043   value[0]=1; // first
00044   value[1]=2;
00045   value[2]=5;
00046   value[3]=2; // second
00047   value[4]=3;
00048   value[5]=5;
00049   value[6]=6;
00050   value[7]=3; // thirst
00051   value[8]=4;
00052   value[9]=6;
00053 
00054   MEDSKYLINEARRAY * myArray = new MEDSKYLINEARRAY(NumberOfCell,Size,index,value) ;
00055 
00056   const int * ArrayIndex ;
00057   try
00058   {
00059         ArrayIndex = myArray->getIndex() ;
00060   }
00061   catch ( const std::exception &e )
00062   {
00063         cout << "----------------" << endl;
00064         cout << "pb avec getIndex" << endl;
00065         cout << "----------------" << endl;
00066         MESSAGE_MED( "catched exception : " << e.what() ) ;
00067         return EXIT_FAILURE ;
00068   }
00069   catch (...)
00070   {
00071         cout << "----------------" << endl;
00072         cout << "pb avec getIndex" << endl;
00073         cout << "----------------" << endl;
00074         return EXIT_FAILURE ;
00075   }
00076 
00077   const int * ArrayValue ;
00078   try
00079   {
00080         ArrayValue  = myArray->getValue() ;
00081   }
00082   catch ( const std::exception &e )
00083   {
00084         cout << "----------------" << endl;
00085         cout << "pb avec getValue" << endl;
00086         cout << "----------------" << endl;
00087         MESSAGE_MED( "catched exception : " << e.what() ) ;
00088         return EXIT_FAILURE ;
00089   }
00090   catch (...)
00091   {
00092         cout << "----------------" << endl;
00093         cout << "pb avec getValue" << endl;
00094         cout << "----------------" << endl;
00095         return EXIT_FAILURE ;
00096   }
00097 
00098 
00099   try
00100   {
00101         ASSERT_MED(myArray->getNumberOf()==NumberOfCell);
00102         cout << myArray->getNumberOf() << endl;
00103   }
00104   catch ( const std::exception &e )
00105   {
00106         cout << "-------------------" << endl;
00107         cout << "pb avec getNumberOf" << endl;
00108         cout << "-------------------" << endl;
00109         MESSAGE_MED( "catched exception : " << e.what() ) ;
00110         return EXIT_FAILURE ;
00111   }
00112   catch (...)
00113   {
00114         cout << "-------------------" << endl;
00115         cout << "pb avec getNumberOf" << endl;
00116         cout << "-------------------" << endl;
00117         return EXIT_FAILURE ;
00118   }
00119 
00120   try
00121   {
00122         ASSERT_MED(myArray->getLength()==Size);
00123         cout << myArray->getLength() << endl; 
00124   }
00125   catch ( const std::exception &e )
00126   {
00127         cout << "-------------------" << endl;
00128         cout << "pb avec getLength" << endl;
00129         cout << "-------------------" << endl;
00130         MESSAGE_MED( "catched exception : " << e.what() ) ;
00131         return EXIT_FAILURE ;
00132   }
00133   catch (...)
00134   {
00135         cout << "-------------------" << endl;
00136         cout << "pb avec getLength" << endl;
00137         cout << "-------------------" << endl;
00138         return EXIT_FAILURE ;
00139   }
00140 
00141   cout << "Show all :" << endl ;
00142   for (int i=1; i< NumberOfCell+1 ; i++) 
00143   {
00144     const int * cell;
00145     try
00146     {
00147         cell = myArray->getI(i) ;
00148     }
00149     catch ( const std::exception &e )
00150     {
00151         cout << "-----------------------------" << endl;
00152         cout << "pb avec getI, valeur de i : " << i << endl;
00153         cout << "-----------------------------" << endl;
00154         MESSAGE_MED( "catched exception : " << e.what() ) ;
00155         return EXIT_FAILURE ;
00156     }
00157     catch (...)
00158     {
00159         cout << "-------------------" << endl;
00160         cout << "pb avec getI, valeur de i : " << i << endl;
00161         cout << "-------------------" << endl;
00162         return EXIT_FAILURE ;
00163     }
00164 
00165     int numberof;
00166     try
00167     {
00168         numberof= myArray->getNumberOfI(i) ;
00169         ASSERT_MED(numberof==index[i]-index[i-1]);
00170     }
00171     catch ( const std::exception &e )
00172     {
00173         cout << "----------------------------------" << endl;
00174         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
00175         cout << "----------------------------------" << endl;
00176         MESSAGE_MED( "catched exception : " << e.what() ) ;
00177         return EXIT_FAILURE ;
00178     }
00179     catch (...)
00180     {
00181         cout << "----------------------------------" << endl;
00182         cout << "pb avec getNumberOfI, valeur de i : " << i << endl;
00183         cout << "----------------------------------" << endl;
00184         return EXIT_FAILURE ;
00185     }
00186 
00187     cout << " - " ;
00188     for (int j=0;j<numberof;j++)
00189     {
00190         cout << cell[j] << " " ;
00191         try
00192         {
00193                 int verif=myArray->getIJ(i,j+1);
00194                 if (verif != cell[j])
00195                 {
00196                         cout << "----------------------------------" << endl;
00197                         cout << " incoherence dans les valeurs :   " << endl;
00198                         cout << " cell[" << j << "] : " << cell[j] << endl;
00199                         cout << " getIJ(" << i <<"," << j << ") : " << verif << endl;
00200                         cout << "----------------------------------" << endl;
00201                         return EXIT_FAILURE ;
00202                 }
00203         }
00204         catch ( const std::exception &e )
00205         {
00206                 cout << "----------------------------------" << endl;
00207                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
00208                 cout << "----------------------------------" << endl;
00209                 MESSAGE_MED( "catched exception : " << e.what() ) ;
00210                 return EXIT_FAILURE ;
00211         }
00212         catch (...)
00213         {
00214                 cout << "----------------------------------" << endl;
00215                 cout << "pb avec getIJ, valeurs de i / j : " << i << " " << j<< endl;
00216                 cout << "----------------------------------" << endl;
00217                 return EXIT_FAILURE ;
00218         }
00219     }
00220     cout << endl ;
00221   }
00222 
00223   delete[] index ;
00224   delete[] value ;
00225 
00226   delete myArray;
00227   MESSAGE_MED("FIN normale du traitement");
00228   return EXIT_SUCCESS ;
00229 
00230 
00231 /*
00232   MEDSKYLINEARRAY( const MEDSKYLINEARRAY &myArray );
00233   void setMEDSKYLINEARRAY( const med_int count, const med_int length, med_int* index , med_int* value ) ;
00234 
00235   
00236 */
00237 }