Back to index

salome-med  6.5.0
MEDMEMTest_ModulusArray.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/Message.h>
00022 #include <cppunit/TestAssert.h>
00023 
00024 #include "MEDMEM_ModulusArray.hxx"
00025 #include "MEDMEM_define.hxx"
00026 
00027 #include <sstream>
00028 #include <cmath>
00029 
00030 using namespace std;
00031 using namespace MEDMEM;
00032 using namespace MED_EN;
00033 
00044 void MEDMEMTest::testModulusArray()
00045 {
00046 
00047   int array[5]={0,1,2,1,4} ;
00048   MEDMODULUSARRAY modulusArray(5,array);
00049 
00050   for(int i=-10, j=0; i<15; i++, j++)
00051     CPPUNIT_ASSERT_EQUAL( array[ j%5 ], modulusArray[i] );
00052 
00053   // test compare
00054   int ret ;
00055 
00056   int array2[5]={1,4,0,1,2} ;
00057   MEDMODULUSARRAY modulusArray2(5,array2);
00058 
00059   ret=modulusArray2.compare(modulusArray);
00060 
00061   CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1);
00062 
00063   int array3[5]={1,2,1,0,4} ;
00064   MEDMODULUSARRAY modulusArray3(5,array3) ;
00065   ret=modulusArray3.compare(modulusArray);
00066 
00067   CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1);
00068 
00069   int array4[6]={1,2,1,0} ;
00070   MEDMODULUSARRAY modulusArray4(4,array4) ;
00071   ret=modulusArray4.compare(modulusArray);
00072 
00073   CPPUNIT_ASSERT_MESSAGE("Two arrays are have different size - KO",ret == 0);
00074 
00075   int array5[5]={1,2,1,0,1} ;
00076   MEDMODULUSARRAY modulusArray5(5,array5) ;
00077 
00078   ret=modulusArray5.compare(modulusArray);
00079 
00080   CPPUNIT_ASSERT_MESSAGE("Two different arrays, same size - KO",ret == 0);
00081 
00082   // test small array :
00083 
00084   // 1
00085   int array6[1]={1} ;
00086   MEDMODULUSARRAY modulusArray6(1,array6);
00087 
00088   for(int i=-10;i<15;i++)
00089     CPPUNIT_ASSERT_EQUAL( 1, modulusArray6[i] );
00090 
00091 
00092   int array7[1]={1} ;
00093   MEDMODULUSARRAY modulusArray7(1,array7);
00094   ret=modulusArray6.compare(modulusArray7);
00095 
00096   CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1);
00097 
00098   int array8[1]={2} ;
00099   MEDMODULUSARRAY modulusArray8(1,array8);
00100   ret=modulusArray6.compare(modulusArray8);
00101 
00102   CPPUNIT_ASSERT_MESSAGE("Two different arrays - KO",ret == 0);
00103 
00104   // 2
00105   int array60[2]={1,2} ;
00106   MEDMODULUSARRAY modulusArray60(2,array60);
00107 
00108   for(int i=-10, j = 0;i<15;i++,j++)
00109     CPPUNIT_ASSERT_EQUAL( array60[ j%2 ], modulusArray60[i] );
00110 
00111   int array70[2]={1,2} ;
00112   MEDMODULUSARRAY modulusArray70(2,array70);
00113 
00114   ret=modulusArray60.compare(modulusArray70);
00115 
00116   CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO",ret == 1);
00117 
00118   int array80[2]={2,2} ;
00119   MEDMODULUSARRAY modulusArray80(2,array80);
00120   ret=modulusArray60.compare(modulusArray80);
00121 
00122   CPPUNIT_ASSERT_MESSAGE("Different arrays - KO",ret == 0);
00123 
00124   int array90[2]={2,1} ;
00125   MEDMODULUSARRAY modulusArray90(2,array90);
00126 
00127   ret=modulusArray60.compare(modulusArray90);
00128 
00129   CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1);
00130 
00131   //test not vertex nodes
00132   int array100[2]={1,2} ;
00133   MEDMODULUSARRAY modulusArray100(2,2,array100); // == MEDMODULUSARRAY(2,array100);
00134 
00135   ret = modulusArray60.compare(modulusArray100);
00136 
00137   CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
00138 
00139   // check comparison of equal arrays, containing non-vertex nodes
00140 
00141   int array110[4] = {1,2,4,3};
00142   MEDMODULUSARRAY modulusArray110(2,4,array110);
00143 
00144   int array120[4] = {1,2,4,3};
00145   MEDMODULUSARRAY modulusArray120(2,4,array120);
00146 
00147   int array130[4] = {1,2,3,4};
00148   MEDMODULUSARRAY modulusArray130(2,4,array130);
00149 
00150   // same order of non-vertex nodes
00151   CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray110));
00152   CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
00153 
00154   // different order of non-vertex nodes
00155   CPPUNIT_ASSERT_NO_THROW(ret = modulusArray130.compare(modulusArray110));
00156   CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
00157 
00158   // check comparison of different arrays, containing non-vertex nodes
00159 
00160   // difference is in vertex nodes
00161   int array140[4] = {1,5,4,3};
00162   MEDMODULUSARRAY modulusArray140 (2,4,array140);
00163 
00164   CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray140));
00165   CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0);
00166 
00167   // difference is in non-vertex nodes
00168   int array150[4] = {1,2,4,5};
00169   MEDMODULUSARRAY modulusArray150 (2,4,array150);
00170 
00171   CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray150));
00172   CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0);
00173 
00174   // check that operator[] returns only vertex nodes
00175   CPPUNIT_ASSERT_EQUAL(1, modulusArray120[0]);
00176   CPPUNIT_ASSERT_EQUAL(2, modulusArray120[1]);
00177   CPPUNIT_ASSERT_EQUAL(1, modulusArray120[2]);
00178   CPPUNIT_ASSERT_EQUAL(2, modulusArray120[3]);
00179   CPPUNIT_ASSERT_EQUAL(1, modulusArray120[4]);
00180   CPPUNIT_ASSERT_EQUAL(2, modulusArray120[5]);
00181 }