Back to index

salome-med  6.5.0
testUModulusArray.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   : testUModulusArray.cxx
00021 //  Module : MED
00022 //
00023 #include <cstdlib>
00024 #include <exception>
00025 #include "MEDMEM_Utilities.hxx"
00026 #include "MEDMEM_ModulusArray.hxx"
00027 using namespace std;
00028 using namespace MEDMEM;
00029 
00030 int main (int argc, char ** argv) 
00031 {
00032 
00033   using namespace std ;
00034 
00035   int array[5]={0,1,2,1,4} ;
00036   MEDMODULUSARRAY modulusArray(5,array);
00037 
00038   cout << " ModulusArray : " << endl;
00039   cout << " _______________" << endl;
00040   for(int i=-10;i<15;i++)
00041   {
00042         cout <<"  - A[" << i <<"]="<<modulusArray[i]<<endl;
00043   }
00044   cout << endl;
00045 
00046   // ------------
00047   // test compare
00048   // ------------
00049 
00050   int ret ;
00051   int array2[5]={1,4,0,1,2} ;
00052   MEDMODULUSARRAY modulusArray2(5,array2) ;
00053 
00054   cout << " Test compare : mÍmes tableaux mÍmes ordres ..." << endl; 
00055 
00056   try
00057   {
00058         ret=modulusArray2.compare(modulusArray);
00059   }
00060   catch ( const std::exception &e )
00061   {
00062         cout << "-----------------" << endl;
00063         cout << " pb avec compare " << endl;
00064         cout << "-----------------" << endl;
00065         MESSAGE_MED( "catched exception : " << e.what() ) ;
00066         return EXIT_FAILURE ;
00067   }
00068   catch (...)
00069   {
00070         cout << "-----------------" << endl;
00071         cout << " pb avec compare " << endl;
00072         cout << "-----------------" << endl;
00073         return EXIT_FAILURE ;
00074   }
00075 
00076   if (ret!=1)
00077   {
00078         cout << "-----------------------------------------------------" << endl;
00079         cout << " pb avec compare entre modulusArray et modulusArray2 " << endl;
00080         cout << " Les deux tableaux sont identiques " << endl;
00081         cout << "-----------------------------------------------------" << endl;
00082         return EXIT_FAILURE ;
00083   }
00084   else
00085   {
00086     cout << " compare entre modulusArray et modulusArray2 :  OK" << endl;
00087     cout << endl;
00088   }
00089 
00090   int array3[5]={1,2,1,0,4} ;
00091   MEDMODULUSARRAY modulusArray3(5,array3) ;
00092 
00093   cout << " Test compare : mÍmes tableaux ordres inverses ..." << endl; 
00094 
00095   try
00096   {
00097         ret=modulusArray3.compare(modulusArray);
00098   }
00099   catch (const std::exception &e )
00100   {
00101         cout << "-----------------" << endl;
00102         cout << " pb avec compare " << endl;
00103         cout << "-----------------" << endl;
00104         MESSAGE_MED( "catched exception : " << e.what() ) ;
00105         return EXIT_FAILURE ;
00106   }
00107   catch (...)
00108   {
00109         cout << "-----------------" << endl;
00110         cout << " pb avec compare " << endl;
00111         cout << "-----------------" << endl;
00112         return EXIT_FAILURE ;
00113   }
00114 
00115   if (ret!=-1)
00116   {
00117         cout << "-----------------------------------------------------" << endl;
00118         cout << " pb avec compare entre modulusArray et modulusArray3 " << endl;
00119         cout << " Les deux tableaux sont inverses " << endl;
00120         cout << "-----------------------------------------------------" << endl;
00121         return EXIT_FAILURE ;
00122   }
00123   else
00124   {
00125     cout << " compare entre modulusArray et modulusArray3 :  OK" << endl;
00126     cout << endl;
00127   }
00128 
00129   int array4[6]={1,2,1,0} ;
00130   MEDMODULUSARRAY modulusArray4(4,array4) ;
00131 
00132   cout << " Test compare : Tableaux de differentes tailles ... " << endl;
00133   try
00134   {
00135         ret=modulusArray4.compare(modulusArray);
00136   }
00137   catch (const std::exception &e )
00138   {
00139         cout << "-----------------" << endl;
00140         cout << " pb avec compare " << endl;
00141         cout << "-----------------" << endl;
00142         MESSAGE_MED( "catched exception : " << e.what() ) ;
00143         return EXIT_FAILURE ;
00144   }
00145   catch (...)
00146   {
00147         cout << "-----------------" << endl;
00148         cout << " pb avec compare " << endl;
00149         cout << "-----------------" << endl;
00150         return EXIT_FAILURE ;
00151   }
00152 
00153   if (ret!=0)
00154   {
00155         cout << "-----------------------------------------------------" << endl;
00156         cout << " pb avec compare entre modulusArray et modulusArray4 " << endl;
00157         cout << " Les deux n ont pas la meme taille "  << endl;
00158         cout << "-----------------------------------------------------" << endl;
00159         return EXIT_FAILURE ;
00160   }
00161   else
00162   {
00163     cout << " compare entre modulusArray et modulusArray4 :  OK" << endl;
00164     cout << endl;
00165   }
00166   
00167   int array5[5]={1,2,1,0,1} ;
00168   MEDMODULUSARRAY modulusArray5(5,array5) ;
00169   cout << " Test compare : tableaux differents de mÍme taille ..." << endl;
00170   try
00171   {
00172         ret=modulusArray5.compare(modulusArray);
00173   }
00174   catch (const std::exception &e )
00175   {
00176         cout << "-----------------" << endl;
00177         cout << " pb avec compare " << endl;
00178         cout << "-----------------" << endl;
00179         MESSAGE_MED( "catched exception : " << e.what() ) ;
00180         return EXIT_FAILURE ;
00181   }
00182   catch (...)
00183   {
00184         cout << "-----------------" << endl;
00185         cout << " pb avec compare " << endl;
00186         cout << "-----------------" << endl;
00187         return EXIT_FAILURE ;
00188   }
00189 
00190   if (ret!=0)
00191   {
00192         cout << "-----------------------------------------------------" << endl;
00193         cout << " pb avec compare entre modulusArray et modulusArray5 " << endl;
00194         cout << " Les deux  tableaux sont differents  "  << endl;
00195         cout << "-----------------------------------------------------" << endl;
00196         return EXIT_FAILURE ;
00197   }
00198   else
00199   {
00200     cout << " compare entre modulusArray et modulusArray5 :  OK" << endl;
00201     cout << endl;
00202   }
00203 
00204   //  test small array :
00205   //  taille 1
00206   int array6[1]={1} ;
00207   MEDMODULUSARRAY modulusArray6(1,array6);
00208 
00209   cout << " ModulusArray  1 : " << endl;
00210   cout << " __________________" << endl;
00211 
00212   for(int i=-10;i<15;i++)
00213   {
00214         cout <<"  - A[" << i <<"]="<<modulusArray6[i]<<endl;
00215   }
00216   cout << endl;
00217 
00218   int array7[1]={1} ;
00219   MEDMODULUSARRAY modulusArray7(1,array7);
00220 
00221   cout << " Test compare : mÍmes tableaux mÍmes ordres ..." << endl;
00222   try
00223   {
00224         ret=modulusArray6.compare(modulusArray7);
00225   }
00226   catch ( const std::exception &e )
00227   {
00228         cout << "-----------------" << endl;
00229         cout << " pb avec compare " << endl;
00230         cout << "-----------------" << endl;
00231         MESSAGE_MED( "catched exception : " << e.what() ) ;
00232         return EXIT_FAILURE ;
00233   }
00234   catch (...)
00235   {
00236         cout << "-----------------" << endl;
00237         cout << " pb avec compare " << endl;
00238         cout << "-----------------" << endl;
00239         return EXIT_FAILURE ;
00240   }
00241 
00242   if (ret!=1)
00243   {
00244         cout << "-----------------------------------------------------" << endl;
00245         cout << " pb avec compare entre modulusArray6 et modulusArray7" << endl;
00246         cout << " Les deux tableaux sont identiques " << endl;
00247         cout << "-----------------------------------------------------" << endl;
00248         return EXIT_FAILURE ;
00249   }
00250   else
00251   {
00252     cout << " compare entre modulusArray6 et modulusArray7 :  OK" << endl ;
00253     cout << endl;
00254   }
00255 
00256   int array8[1]={2} ;
00257   MEDMODULUSARRAY modulusArray8(1,array8);
00258 
00259    cout << " Test compare : tableaux differents "<< endl;
00260   try
00261   {
00262         ret=modulusArray6.compare(modulusArray8);
00263  }
00264   catch ( const std::exception &e )
00265   {
00266         cout << "-----------------" << endl;
00267         cout << " pb avec compare " << endl;
00268         cout << "-----------------" << endl;
00269         MESSAGE_MED( "catched exception : " << e.what() ) ;
00270         return EXIT_FAILURE ;
00271   }
00272   catch (...)
00273   {
00274         cout << "-----------------" << endl;
00275         cout << " pb avec compare " << endl;
00276         cout << "-----------------" << endl;
00277         return EXIT_FAILURE ;
00278   }
00279   
00280   if (ret!=0)
00281   {
00282         cout << "-----------------------------------------------------" << endl;
00283         cout << " pb avec compare entre modulusArray6 et modulusArray8" << endl;
00284         cout << " Les deux tableaux sont  differents" << endl;
00285         cout << "-----------------------------------------------------" << endl;
00286         return EXIT_FAILURE ;
00287   }
00288   else
00289   {
00290     cout << " compare entre modulusArray6 et modulusArray8 :  OK" << endl;
00291     cout << endl;
00292   }
00293 
00294   
00295   // 2
00296   int array60[2]={1,2} ;
00297   MEDMODULUSARRAY modulusArray60(2,array60);
00298 
00299 
00300   cout << " ModulusArray  2 : " << endl;
00301   cout << " __________________" << endl;
00302 
00303   for(int i=-10;i<15;i++)
00304   {
00305         cout <<"  - A[" << i <<"]="<<modulusArray60[i]<<endl;
00306   }
00307   cout << endl;
00308 
00309   int array70[2]={1,2} ;
00310   MEDMODULUSARRAY modulusArray70(2,array70);
00311   cout << " Test compare : mÍmes tableaux mÍmes ordres ..." << endl;
00312 
00313   try
00314   {
00315         ret=modulusArray60.compare(modulusArray70);
00316   }
00317   catch ( const std::exception &e )
00318   {
00319         cout << "-----------------" << endl;
00320         cout << " pb avec compare " << endl;
00321         cout << "-----------------" << endl;
00322         MESSAGE_MED( "catched exception : " << e.what() ) ;
00323         return EXIT_FAILURE ;
00324   }
00325   catch (...)
00326   {
00327         cout << "-----------------" << endl;
00328         cout << " pb avec compare " << endl;
00329         cout << "-----------------" << endl;
00330         return EXIT_FAILURE ;
00331   }
00332 
00333   if (ret!=1)
00334   {
00335         cout << "--------------------------------------------------------" << endl;
00336         cout << " pb avec compare entre modulusArray60 et modulusArray70 " << endl;
00337         cout << " Les deux tableaux sont identiques " << endl;
00338         cout << "--------------------------------------------------------" << endl;
00339         return EXIT_FAILURE ;
00340   }
00341   else
00342   {
00343     cout << " compare entre modulusArray60 et modulusArray70 :  OK" << endl;
00344     cout << endl;
00345   }
00346 
00347   int array80[2]={2,2} ;
00348   MEDMODULUSARRAY modulusArray80(2,array80);
00349 
00350   cout << " Test compare : tableaux differents  ..." << endl;
00351 
00352   try
00353   {
00354         ret=modulusArray60.compare(modulusArray80);
00355   }
00356   catch ( const std::exception &e )
00357   {
00358         cout << "-----------------" << endl;
00359         cout << " pb avec compare " << endl;
00360         cout << "-----------------" << endl;
00361         MESSAGE_MED( "catched exception : " << e.what() ) ;
00362         return EXIT_FAILURE ;
00363   }
00364   catch (...)
00365   {
00366         cout << "-----------------" << endl;
00367         cout << " pb avec compare " << endl;
00368         cout << "-----------------" << endl;
00369         return EXIT_FAILURE ;
00370   }
00371 
00372   if (ret!=0)
00373   {
00374         cout << "--------------------------------------------------------" << endl;
00375         cout << " pb avec compare entre modulusArray60 et modulusArray80 " << endl;
00376         cout << " Les deux tableaux sont differents " << endl;
00377         cout << "--------------------------------------------------------" << endl;
00378         return EXIT_FAILURE ;
00379   }
00380   else
00381   {
00382     cout << " compare entre modulusArray60 et modulusArray80 :  OK" << endl;
00383     cout << endl;
00384   }
00385 
00386   int array90[2]={2,1} ;
00387   MEDMODULUSARRAY modulusArray90(2,array90);
00388   cout << " Test compare : tableaux differents ordres inverses ..." << endl;
00389   try
00390   {
00391         ret=modulusArray60.compare(modulusArray90);
00392   }
00393   catch ( const std::exception &e )
00394   {
00395         cout << "-----------------" << endl;
00396         cout << " pb avec compare " << endl;
00397         cout << "-----------------" << endl;
00398         MESSAGE_MED( "catched exception : " << e.what() ) ;
00399         return EXIT_FAILURE ;
00400   }
00401   catch (...)
00402   {
00403         cout << "-----------------" << endl;
00404         cout << " pb avec compare " << endl;
00405         cout << "-----------------" << endl;
00406         return EXIT_FAILURE ;
00407   }
00408 
00409   if (ret!=-1)
00410   {
00411         cout << "--------------------------------------------------------" << endl;
00412         cout << " pb avec compare entre modulusArray60 et modulusArray90 " << endl;
00413         cout << " Les deux tableaux sont differents " << endl;
00414         cout << "--------------------------------------------------------" << endl;
00415         return EXIT_FAILURE ;
00416   }
00417   else
00418   {
00419     cout << " compare entre modulusArray60 et modulusArray90 :  OK" << endl;
00420     cout << endl;
00421   }
00422 
00423   return EXIT_SUCCESS ;
00424 }