1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDMEMTest.hxx"
21 #include <cppunit/Message.h>
22 #include <cppunit/TestAssert.h>
24 #include "MEDMEM_ModulusArray.hxx"
25 #include "MEDMEM_define.hxx"
31 using namespace MEDMEM;
32 using namespace MED_EN;
35 * Check methods (4), defined in MEDMEM_ModulusArray.hxx:
36 * class MEDMODULUSARRAY {
37 * (+) MEDMODULUSARRAY(int length, const int * array);
38 * (+) MEDMODULUSARRAY(int vertexLength, int totalLength, const int * array);
39 * (+) ~MEDMODULUSARRAY();
40 * (+) const int operator[](const int &i) const;
41 * (+) int compare(const MEDMODULUSARRAY &modulusArray) const;
44 void MEDMEMTest::testModulusArray()
47 int array[5]={0,1,2,1,4} ;
48 MEDMODULUSARRAY modulusArray(5,array);
50 for(int i=-10, j=0; i<15; i++, j++)
51 CPPUNIT_ASSERT_EQUAL( array[ j%5 ], modulusArray[i] );
56 int array2[5]={1,4,0,1,2} ;
57 MEDMODULUSARRAY modulusArray2(5,array2);
59 ret=modulusArray2.compare(modulusArray);
61 CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1);
63 int array3[5]={1,2,1,0,4} ;
64 MEDMODULUSARRAY modulusArray3(5,array3) ;
65 ret=modulusArray3.compare(modulusArray);
67 CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1);
69 int array4[6]={1,2,1,0} ;
70 MEDMODULUSARRAY modulusArray4(4,array4) ;
71 ret=modulusArray4.compare(modulusArray);
73 CPPUNIT_ASSERT_MESSAGE("Two arrays are have different size - KO",ret == 0);
75 int array5[5]={1,2,1,0,1} ;
76 MEDMODULUSARRAY modulusArray5(5,array5) ;
78 ret=modulusArray5.compare(modulusArray);
80 CPPUNIT_ASSERT_MESSAGE("Two different arrays, same size - KO",ret == 0);
86 MEDMODULUSARRAY modulusArray6(1,array6);
88 for(int i=-10;i<15;i++)
89 CPPUNIT_ASSERT_EQUAL( 1, modulusArray6[i] );
93 MEDMODULUSARRAY modulusArray7(1,array7);
94 ret=modulusArray6.compare(modulusArray7);
96 CPPUNIT_ASSERT_MESSAGE("Two identical arrays - KO", ret == 1);
99 MEDMODULUSARRAY modulusArray8(1,array8);
100 ret=modulusArray6.compare(modulusArray8);
102 CPPUNIT_ASSERT_MESSAGE("Two different arrays - KO",ret == 0);
105 int array60[2]={1,2} ;
106 MEDMODULUSARRAY modulusArray60(2,array60);
108 for(int i=-10, j = 0;i<15;i++,j++)
109 CPPUNIT_ASSERT_EQUAL( array60[ j%2 ], modulusArray60[i] );
111 int array70[2]={1,2} ;
112 MEDMODULUSARRAY modulusArray70(2,array70);
114 ret=modulusArray60.compare(modulusArray70);
116 CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO",ret == 1);
118 int array80[2]={2,2} ;
119 MEDMODULUSARRAY modulusArray80(2,array80);
120 ret=modulusArray60.compare(modulusArray80);
122 CPPUNIT_ASSERT_MESSAGE("Different arrays - KO",ret == 0);
124 int array90[2]={2,1} ;
125 MEDMODULUSARRAY modulusArray90(2,array90);
127 ret=modulusArray60.compare(modulusArray90);
129 CPPUNIT_ASSERT_MESSAGE("Two arrays are in reverse order - KO",ret == -1);
131 //test not vertex nodes
132 int array100[2]={1,2} ;
133 MEDMODULUSARRAY modulusArray100(2,2,array100); // == MEDMODULUSARRAY(2,array100);
135 ret = modulusArray60.compare(modulusArray100);
137 CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
139 // check comparison of equal arrays, containing non-vertex nodes
141 int array110[4] = {1,2,4,3};
142 MEDMODULUSARRAY modulusArray110(2,4,array110);
144 int array120[4] = {1,2,4,3};
145 MEDMODULUSARRAY modulusArray120(2,4,array120);
147 int array130[4] = {1,2,3,4};
148 MEDMODULUSARRAY modulusArray130(2,4,array130);
150 // same order of non-vertex nodes
151 CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray110));
152 CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
154 // different order of non-vertex nodes
155 CPPUNIT_ASSERT_NO_THROW(ret = modulusArray130.compare(modulusArray110));
156 CPPUNIT_ASSERT_MESSAGE("Same arrays, same order - KO", ret == 1);
158 // check comparison of different arrays, containing non-vertex nodes
160 // difference is in vertex nodes
161 int array140[4] = {1,5,4,3};
162 MEDMODULUSARRAY modulusArray140 (2,4,array140);
164 CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray140));
165 CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0);
167 // difference is in non-vertex nodes
168 int array150[4] = {1,2,4,5};
169 MEDMODULUSARRAY modulusArray150 (2,4,array150);
171 CPPUNIT_ASSERT_NO_THROW(ret = modulusArray120.compare(modulusArray150));
172 CPPUNIT_ASSERT_MESSAGE("Different arrays - KO", ret == 0);
174 // check that operator[] returns only vertex nodes
175 CPPUNIT_ASSERT_EQUAL(1, modulusArray120[0]);
176 CPPUNIT_ASSERT_EQUAL(2, modulusArray120[1]);
177 CPPUNIT_ASSERT_EQUAL(1, modulusArray120[2]);
178 CPPUNIT_ASSERT_EQUAL(2, modulusArray120[3]);
179 CPPUNIT_ASSERT_EQUAL(1, modulusArray120[4]);
180 CPPUNIT_ASSERT_EQUAL(2, modulusArray120[5]);