Salome HOME
Final version of the V2_2_0 in the main trunk of the CVS tree.
[modules/med.git] / src / MEDMEM / tests / testUModulusArray.cxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19 //
20 //
21 //
22 //  File   : testUModulusArray.cxx
23 //  Module : MED
24
25 #include <cstdlib>
26 #include <exception>
27 #include "utilities.h"
28 #include "MEDMEM_ModulusArray.hxx"
29 using namespace std;
30 using namespace MEDMEM;
31
32 int main (int argc, char ** argv) 
33 {
34
35   using namespace std ;
36
37   int array[5]={0,1,2,1,4} ;
38   MEDMODULUSARRAY modulusArray(5,array);
39
40   cout << " ModulusArray : " << endl;
41   cout << " _______________" << endl;
42   for(int i=-10;i<15;i++)
43   {
44         cout <<"  - A[" << i <<"]="<<modulusArray[i]<<endl;
45   }
46   cout << endl;
47
48   // ------------
49   // test compare
50   // ------------
51
52   int ret ;
53   int array2[5]={1,4,0,1,2} ;
54   MEDMODULUSARRAY modulusArray2(5,array2) ;
55
56   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl; 
57
58   try
59   {
60         ret=modulusArray2.compare(modulusArray);
61   }
62   catch ( const std::exception &e )
63   {
64         cout << "-----------------" << endl;
65         cout << " pb avec compare " << endl;
66         cout << "-----------------" << endl;
67         MESSAGE( "catched exception : " << e.what() ) ;
68         return EXIT_FAILURE ;
69   }
70   catch (...)
71   {
72         cout << "-----------------" << endl;
73         cout << " pb avec compare " << endl;
74         cout << "-----------------" << endl;
75         return EXIT_FAILURE ;
76   }
77
78   if (ret!=1)
79   {
80         cout << "-----------------------------------------------------" << endl;
81         cout << " pb avec compare entre modulusArray et modulusArray2 " << endl;
82         cout << " Les deux tableaux sont identiques " << endl;
83         cout << "-----------------------------------------------------" << endl;
84         return EXIT_FAILURE ;
85   }
86   else
87   {
88     cout << " compare entre modulusArray et modulusArray2 :  OK" << endl;
89     cout << endl;
90   }
91
92   int array3[5]={1,2,1,0,4} ;
93   MEDMODULUSARRAY modulusArray3(5,array3) ;
94
95   cout << " Test compare : mêmes tableaux ordres inverses ..." << endl; 
96
97   try
98   {
99         ret=modulusArray3.compare(modulusArray);
100   }
101   catch (const std::exception &e )
102   {
103         cout << "-----------------" << endl;
104         cout << " pb avec compare " << endl;
105         cout << "-----------------" << endl;
106         MESSAGE( "catched exception : " << e.what() ) ;
107         return EXIT_FAILURE ;
108   }
109   catch (...)
110   {
111         cout << "-----------------" << endl;
112         cout << " pb avec compare " << endl;
113         cout << "-----------------" << endl;
114         return EXIT_FAILURE ;
115   }
116
117   if (ret!=-1)
118   {
119         cout << "-----------------------------------------------------" << endl;
120         cout << " pb avec compare entre modulusArray et modulusArray3 " << endl;
121         cout << " Les deux tableaux sont inverses " << endl;
122         cout << "-----------------------------------------------------" << endl;
123         return EXIT_FAILURE ;
124   }
125   else
126   {
127     cout << " compare entre modulusArray et modulusArray3 :  OK" << endl;
128     cout << endl;
129   }
130
131   int array4[6]={1,2,1,0} ;
132   MEDMODULUSARRAY modulusArray4(4,array4) ;
133
134   cout << " Test compare : Tableaux de differentes tailles ... " << endl;
135   try
136   {
137         ret=modulusArray4.compare(modulusArray);
138   }
139   catch (const std::exception &e )
140   {
141         cout << "-----------------" << endl;
142         cout << " pb avec compare " << endl;
143         cout << "-----------------" << endl;
144         MESSAGE( "catched exception : " << e.what() ) ;
145         return EXIT_FAILURE ;
146   }
147   catch (...)
148   {
149         cout << "-----------------" << endl;
150         cout << " pb avec compare " << endl;
151         cout << "-----------------" << endl;
152         return EXIT_FAILURE ;
153   }
154
155   if (ret!=0)
156   {
157         cout << "-----------------------------------------------------" << endl;
158         cout << " pb avec compare entre modulusArray et modulusArray4 " << endl;
159         cout << " Les deux n ont pas la meme taille "  << endl;
160         cout << "-----------------------------------------------------" << endl;
161         return EXIT_FAILURE ;
162   }
163   else
164   {
165     cout << " compare entre modulusArray et modulusArray4 :  OK" << endl;
166     cout << endl;
167   }
168   
169   int array5[5]={1,2,1,0,1} ;
170   MEDMODULUSARRAY modulusArray5(5,array5) ;
171   cout << " Test compare : tableaux differents de même taille ..." << endl;
172   try
173   {
174         ret=modulusArray5.compare(modulusArray);
175   }
176   catch (const std::exception &e )
177   {
178         cout << "-----------------" << endl;
179         cout << " pb avec compare " << endl;
180         cout << "-----------------" << endl;
181         MESSAGE( "catched exception : " << e.what() ) ;
182         return EXIT_FAILURE ;
183   }
184   catch (...)
185   {
186         cout << "-----------------" << endl;
187         cout << " pb avec compare " << endl;
188         cout << "-----------------" << endl;
189         return EXIT_FAILURE ;
190   }
191
192   if (ret!=0)
193   {
194         cout << "-----------------------------------------------------" << endl;
195         cout << " pb avec compare entre modulusArray et modulusArray5 " << endl;
196         cout << " Les deux  tableaux sont differents  "  << endl;
197         cout << "-----------------------------------------------------" << endl;
198         return EXIT_FAILURE ;
199   }
200   else
201   {
202     cout << " compare entre modulusArray et modulusArray5 :  OK" << endl;
203     cout << endl;
204   }
205
206   //  test small array :
207   //  taille 1
208   int array6[1]={1} ;
209   MEDMODULUSARRAY modulusArray6(1,array6);
210
211   cout << " ModulusArray  1 : " << endl;
212   cout << " __________________" << endl;
213
214   for(int i=-10;i<15;i++)
215   {
216         cout <<"  - A[" << i <<"]="<<modulusArray6[i]<<endl;
217   }
218   cout << endl;
219
220   int array7[1]={1} ;
221   MEDMODULUSARRAY modulusArray7(1,array7);
222
223   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl;
224   try
225   {
226         ret=modulusArray6.compare(modulusArray7);
227   }
228   catch ( const std::exception &e )
229   {
230         cout << "-----------------" << endl;
231         cout << " pb avec compare " << endl;
232         cout << "-----------------" << endl;
233         MESSAGE( "catched exception : " << e.what() ) ;
234         return EXIT_FAILURE ;
235   }
236   catch (...)
237   {
238         cout << "-----------------" << endl;
239         cout << " pb avec compare " << endl;
240         cout << "-----------------" << endl;
241         return EXIT_FAILURE ;
242   }
243
244   if (ret!=1)
245   {
246         cout << "-----------------------------------------------------" << endl;
247         cout << " pb avec compare entre modulusArray6 et modulusArray7" << endl;
248         cout << " Les deux tableaux sont identiques " << endl;
249         cout << "-----------------------------------------------------" << endl;
250         return EXIT_FAILURE ;
251   }
252   else
253   {
254     cout << " compare entre modulusArray6 et modulusArray7 :  OK" << endl ;
255     cout << endl;
256   }
257
258   int array8[1]={2} ;
259   MEDMODULUSARRAY modulusArray8(1,array8);
260
261    cout << " Test compare : tableaux differents "<< endl;
262   try
263   {
264         ret=modulusArray6.compare(modulusArray8);
265  }
266   catch ( const std::exception &e )
267   {
268         cout << "-----------------" << endl;
269         cout << " pb avec compare " << endl;
270         cout << "-----------------" << endl;
271         MESSAGE( "catched exception : " << e.what() ) ;
272         return EXIT_FAILURE ;
273   }
274   catch (...)
275   {
276         cout << "-----------------" << endl;
277         cout << " pb avec compare " << endl;
278         cout << "-----------------" << endl;
279         return EXIT_FAILURE ;
280   }
281   
282   if (ret!=0)
283   {
284         cout << "-----------------------------------------------------" << endl;
285         cout << " pb avec compare entre modulusArray6 et modulusArray8" << endl;
286         cout << " Les deux tableaux sont  differents" << endl;
287         cout << "-----------------------------------------------------" << endl;
288         return EXIT_FAILURE ;
289   }
290   else
291   {
292     cout << " compare entre modulusArray6 et modulusArray8 :  OK" << endl;
293     cout << endl;
294   }
295
296   
297   // 2
298   int array60[2]={1,2} ;
299   MEDMODULUSARRAY modulusArray60(2,array60);
300
301
302   cout << " ModulusArray  2 : " << endl;
303   cout << " __________________" << endl;
304
305   for(int i=-10;i<15;i++)
306   {
307         cout <<"  - A[" << i <<"]="<<modulusArray60[i]<<endl;
308   }
309   cout << endl;
310
311   int array70[2]={1,2} ;
312   MEDMODULUSARRAY modulusArray70(2,array70);
313   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl;
314
315   try
316   {
317         ret=modulusArray60.compare(modulusArray70);
318   }
319   catch ( const std::exception &e )
320   {
321         cout << "-----------------" << endl;
322         cout << " pb avec compare " << endl;
323         cout << "-----------------" << endl;
324         MESSAGE( "catched exception : " << e.what() ) ;
325         return EXIT_FAILURE ;
326   }
327   catch (...)
328   {
329         cout << "-----------------" << endl;
330         cout << " pb avec compare " << endl;
331         cout << "-----------------" << endl;
332         return EXIT_FAILURE ;
333   }
334
335   if (ret!=1)
336   {
337         cout << "--------------------------------------------------------" << endl;
338         cout << " pb avec compare entre modulusArray60 et modulusArray70 " << endl;
339         cout << " Les deux tableaux sont identiques " << endl;
340         cout << "--------------------------------------------------------" << endl;
341         return EXIT_FAILURE ;
342   }
343   else
344   {
345     cout << " compare entre modulusArray60 et modulusArray70 :  OK" << endl;
346     cout << endl;
347   }
348
349   int array80[2]={2,2} ;
350   MEDMODULUSARRAY modulusArray80(2,array80);
351
352   cout << " Test compare : tableaux differents  ..." << endl;
353
354   try
355   {
356         ret=modulusArray60.compare(modulusArray80);
357   }
358   catch ( const std::exception &e )
359   {
360         cout << "-----------------" << endl;
361         cout << " pb avec compare " << endl;
362         cout << "-----------------" << endl;
363         MESSAGE( "catched exception : " << e.what() ) ;
364         return EXIT_FAILURE ;
365   }
366   catch (...)
367   {
368         cout << "-----------------" << endl;
369         cout << " pb avec compare " << endl;
370         cout << "-----------------" << endl;
371         return EXIT_FAILURE ;
372   }
373
374   if (ret!=0)
375   {
376         cout << "--------------------------------------------------------" << endl;
377         cout << " pb avec compare entre modulusArray60 et modulusArray80 " << endl;
378         cout << " Les deux tableaux sont differents " << endl;
379         cout << "--------------------------------------------------------" << endl;
380         return EXIT_FAILURE ;
381   }
382   else
383   {
384     cout << " compare entre modulusArray60 et modulusArray80 :  OK" << endl;
385     cout << endl;
386   }
387
388   int array90[2]={2,1} ;
389   MEDMODULUSARRAY modulusArray90(2,array90);
390   cout << " Test compare : tableaux differents ordres inverses ..." << endl;
391   try
392   {
393         ret=modulusArray60.compare(modulusArray90);
394   }
395   catch ( const std::exception &e )
396   {
397         cout << "-----------------" << endl;
398         cout << " pb avec compare " << endl;
399         cout << "-----------------" << endl;
400         MESSAGE( "catched exception : " << e.what() ) ;
401         return EXIT_FAILURE ;
402   }
403   catch (...)
404   {
405         cout << "-----------------" << endl;
406         cout << " pb avec compare " << endl;
407         cout << "-----------------" << endl;
408         return EXIT_FAILURE ;
409   }
410
411   if (ret!=-1)
412   {
413         cout << "--------------------------------------------------------" << endl;
414         cout << " pb avec compare entre modulusArray60 et modulusArray90 " << endl;
415         cout << " Les deux tableaux sont differents " << endl;
416         cout << "--------------------------------------------------------" << endl;
417         return EXIT_FAILURE ;
418   }
419   else
420   {
421     cout << " compare entre modulusArray60 et modulusArray90 :  OK" << endl;
422     cout << endl;
423   }
424
425   return EXIT_SUCCESS ;
426 }