Salome HOME
sources v1.2
[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 using namespace std;
26 #include <cstdlib>
27 #include <exception>
28 #include "utilities.h"
29 #include "MEDMEM_ModulusArray.hxx"
30
31 int main (int argc, char ** argv) 
32 {
33
34   using namespace std ;
35
36   int array[5]={0,1,2,1,4} ;
37   MEDMODULUSARRAY modulusArray(5,array);
38
39   cout << " ModulusArray : " << endl;
40   cout << " _______________" << endl;
41   for(int i=-10;i<15;i++)
42   {
43         cout <<"  - A[" << i <<"]="<<modulusArray[i]<<endl;
44   }
45   cout << endl;
46
47   // ------------
48   // test compare
49   // ------------
50
51   int ret ;
52   int array2[5]={1,4,0,1,2} ;
53   MEDMODULUSARRAY modulusArray2(5,array2) ;
54
55   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl; 
56
57   try
58   {
59         ret=modulusArray2.compare(modulusArray);
60   }
61   catch ( const std::exception &e )
62   {
63         cout << "-----------------" << endl;
64         cout << " pb avec compare " << endl;
65         cout << "-----------------" << endl;
66         MESSAGE( "catched exception : " << e.what() ) ;
67         return EXIT_FAILURE ;
68   }
69   catch (...)
70   {
71         cout << "-----------------" << endl;
72         cout << " pb avec compare " << endl;
73         cout << "-----------------" << endl;
74         return EXIT_FAILURE ;
75   }
76
77   if (ret!=1)
78   {
79         cout << "-----------------------------------------------------" << endl;
80         cout << " pb avec compare entre modulusArray et modulusArray2 " << endl;
81         cout << " Les deux tableaux sont identiques " << endl;
82         cout << "-----------------------------------------------------" << endl;
83         return EXIT_FAILURE ;
84   }
85   else
86   {
87     cout << " compare entre modulusArray et modulusArray2 :  OK" << endl;
88     cout << endl;
89   }
90
91   int array3[5]={1,2,1,0,4} ;
92   MEDMODULUSARRAY modulusArray3(5,array3) ;
93
94   cout << " Test compare : mêmes tableaux ordres inverses ..." << endl; 
95
96   try
97   {
98         ret=modulusArray3.compare(modulusArray);
99   }
100   catch (const std::exception &e )
101   {
102         cout << "-----------------" << endl;
103         cout << " pb avec compare " << endl;
104         cout << "-----------------" << endl;
105         MESSAGE( "catched exception : " << e.what() ) ;
106         return EXIT_FAILURE ;
107   }
108   catch (...)
109   {
110         cout << "-----------------" << endl;
111         cout << " pb avec compare " << endl;
112         cout << "-----------------" << endl;
113         return EXIT_FAILURE ;
114   }
115
116   if (ret!=-1)
117   {
118         cout << "-----------------------------------------------------" << endl;
119         cout << " pb avec compare entre modulusArray et modulusArray3 " << endl;
120         cout << " Les deux tableaux sont inverses " << endl;
121         cout << "-----------------------------------------------------" << endl;
122         return EXIT_FAILURE ;
123   }
124   else
125   {
126     cout << " compare entre modulusArray et modulusArray3 :  OK" << endl;
127     cout << endl;
128   }
129
130   int array4[6]={1,2,1,0} ;
131   MEDMODULUSARRAY modulusArray4(4,array4) ;
132
133   cout << " Test compare : Tableaux de differentes tailles ... " << endl;
134   try
135   {
136         ret=modulusArray4.compare(modulusArray);
137   }
138   catch (const std::exception &e )
139   {
140         cout << "-----------------" << endl;
141         cout << " pb avec compare " << endl;
142         cout << "-----------------" << endl;
143         MESSAGE( "catched exception : " << e.what() ) ;
144         return EXIT_FAILURE ;
145   }
146   catch (...)
147   {
148         cout << "-----------------" << endl;
149         cout << " pb avec compare " << endl;
150         cout << "-----------------" << endl;
151         return EXIT_FAILURE ;
152   }
153
154   if (ret!=0)
155   {
156         cout << "-----------------------------------------------------" << endl;
157         cout << " pb avec compare entre modulusArray et modulusArray4 " << endl;
158         cout << " Les deux n ont pas la meme taille "  << endl;
159         cout << "-----------------------------------------------------" << endl;
160         return EXIT_FAILURE ;
161   }
162   else
163   {
164     cout << " compare entre modulusArray et modulusArray4 :  OK" << endl;
165     cout << endl;
166   }
167   
168   int array5[5]={1,2,1,0,1} ;
169   MEDMODULUSARRAY modulusArray5(5,array5) ;
170   cout << " Test compare : tableaux differents de même taille ..." << endl;
171   try
172   {
173         ret=modulusArray5.compare(modulusArray);
174   }
175   catch (const std::exception &e )
176   {
177         cout << "-----------------" << endl;
178         cout << " pb avec compare " << endl;
179         cout << "-----------------" << endl;
180         MESSAGE( "catched exception : " << e.what() ) ;
181         return EXIT_FAILURE ;
182   }
183   catch (...)
184   {
185         cout << "-----------------" << endl;
186         cout << " pb avec compare " << endl;
187         cout << "-----------------" << endl;
188         return EXIT_FAILURE ;
189   }
190
191   if (ret!=0)
192   {
193         cout << "-----------------------------------------------------" << endl;
194         cout << " pb avec compare entre modulusArray et modulusArray5 " << endl;
195         cout << " Les deux  tableaux sont differents  "  << endl;
196         cout << "-----------------------------------------------------" << endl;
197         return EXIT_FAILURE ;
198   }
199   else
200   {
201     cout << " compare entre modulusArray et modulusArray5 :  OK" << endl;
202     cout << endl;
203   }
204
205   //  test small array :
206   //  taille 1
207   int array6[1]={1} ;
208   MEDMODULUSARRAY modulusArray6(1,array6);
209
210   cout << " ModulusArray  1 : " << endl;
211   cout << " __________________" << endl;
212
213   for(int i=-10;i<15;i++)
214   {
215         cout <<"  - A[" << i <<"]="<<modulusArray6[i]<<endl;
216   }
217   cout << endl;
218
219   int array7[1]={1} ;
220   MEDMODULUSARRAY modulusArray7(1,array7);
221
222   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl;
223   try
224   {
225         ret=modulusArray6.compare(modulusArray7);
226   }
227   catch ( const std::exception &e )
228   {
229         cout << "-----------------" << endl;
230         cout << " pb avec compare " << endl;
231         cout << "-----------------" << endl;
232         MESSAGE( "catched exception : " << e.what() ) ;
233         return EXIT_FAILURE ;
234   }
235   catch (...)
236   {
237         cout << "-----------------" << endl;
238         cout << " pb avec compare " << endl;
239         cout << "-----------------" << endl;
240         return EXIT_FAILURE ;
241   }
242
243   if (ret!=1)
244   {
245         cout << "-----------------------------------------------------" << endl;
246         cout << " pb avec compare entre modulusArray6 et modulusArray7" << endl;
247         cout << " Les deux tableaux sont identiques " << endl;
248         cout << "-----------------------------------------------------" << endl;
249         return EXIT_FAILURE ;
250   }
251   else
252   {
253     cout << " compare entre modulusArray6 et modulusArray7 :  OK" << endl ;
254     cout << endl;
255   }
256
257   int array8[1]={2} ;
258   MEDMODULUSARRAY modulusArray8(1,array8);
259
260    cout << " Test compare : tableaux differents "<< endl;
261   try
262   {
263         ret=modulusArray6.compare(modulusArray8);
264  }
265   catch ( const std::exception &e )
266   {
267         cout << "-----------------" << endl;
268         cout << " pb avec compare " << endl;
269         cout << "-----------------" << endl;
270         MESSAGE( "catched exception : " << e.what() ) ;
271         return EXIT_FAILURE ;
272   }
273   catch (...)
274   {
275         cout << "-----------------" << endl;
276         cout << " pb avec compare " << endl;
277         cout << "-----------------" << endl;
278         return EXIT_FAILURE ;
279   }
280   
281   if (ret!=0)
282   {
283         cout << "-----------------------------------------------------" << endl;
284         cout << " pb avec compare entre modulusArray6 et modulusArray8" << endl;
285         cout << " Les deux tableaux sont  differents" << endl;
286         cout << "-----------------------------------------------------" << endl;
287         return EXIT_FAILURE ;
288   }
289   else
290   {
291     cout << " compare entre modulusArray6 et modulusArray8 :  OK" << endl;
292     cout << endl;
293   }
294
295   
296   // 2
297   int array60[2]={1,2} ;
298   MEDMODULUSARRAY modulusArray60(2,array60);
299
300
301   cout << " ModulusArray  2 : " << endl;
302   cout << " __________________" << endl;
303
304   for(int i=-10;i<15;i++)
305   {
306         cout <<"  - A[" << i <<"]="<<modulusArray60[i]<<endl;
307   }
308   cout << endl;
309
310   int array70[2]={1,2} ;
311   MEDMODULUSARRAY modulusArray70(2,array70);
312   cout << " Test compare : mêmes tableaux mêmes ordres ..." << endl;
313
314   try
315   {
316         ret=modulusArray60.compare(modulusArray70);
317   }
318   catch ( const std::exception &e )
319   {
320         cout << "-----------------" << endl;
321         cout << " pb avec compare " << endl;
322         cout << "-----------------" << endl;
323         MESSAGE( "catched exception : " << e.what() ) ;
324         return EXIT_FAILURE ;
325   }
326   catch (...)
327   {
328         cout << "-----------------" << endl;
329         cout << " pb avec compare " << endl;
330         cout << "-----------------" << endl;
331         return EXIT_FAILURE ;
332   }
333
334   if (ret!=1)
335   {
336         cout << "--------------------------------------------------------" << endl;
337         cout << " pb avec compare entre modulusArray60 et modulusArray70 " << endl;
338         cout << " Les deux tableaux sont identiques " << endl;
339         cout << "--------------------------------------------------------" << endl;
340         return EXIT_FAILURE ;
341   }
342   else
343   {
344     cout << " compare entre modulusArray60 et modulusArray70 :  OK" << endl;
345     cout << endl;
346   }
347
348   int array80[2]={2,2} ;
349   MEDMODULUSARRAY modulusArray80(2,array80);
350
351   cout << " Test compare : tableaux differents  ..." << endl;
352
353   try
354   {
355         ret=modulusArray60.compare(modulusArray80);
356   }
357   catch ( const std::exception &e )
358   {
359         cout << "-----------------" << endl;
360         cout << " pb avec compare " << endl;
361         cout << "-----------------" << endl;
362         MESSAGE( "catched exception : " << e.what() ) ;
363         return EXIT_FAILURE ;
364   }
365   catch (...)
366   {
367         cout << "-----------------" << endl;
368         cout << " pb avec compare " << endl;
369         cout << "-----------------" << endl;
370         return EXIT_FAILURE ;
371   }
372
373   if (ret!=0)
374   {
375         cout << "--------------------------------------------------------" << endl;
376         cout << " pb avec compare entre modulusArray60 et modulusArray80 " << endl;
377         cout << " Les deux tableaux sont differents " << endl;
378         cout << "--------------------------------------------------------" << endl;
379         return EXIT_FAILURE ;
380   }
381   else
382   {
383     cout << " compare entre modulusArray60 et modulusArray80 :  OK" << endl;
384     cout << endl;
385   }
386
387   int array90[2]={2,1} ;
388   MEDMODULUSARRAY modulusArray90(2,array90);
389   cout << " Test compare : tableaux differents ordres inverses ..." << endl;
390   try
391   {
392         ret=modulusArray60.compare(modulusArray90);
393   }
394   catch ( const std::exception &e )
395   {
396         cout << "-----------------" << endl;
397         cout << " pb avec compare " << endl;
398         cout << "-----------------" << endl;
399         MESSAGE( "catched exception : " << e.what() ) ;
400         return EXIT_FAILURE ;
401   }
402   catch (...)
403   {
404         cout << "-----------------" << endl;
405         cout << " pb avec compare " << endl;
406         cout << "-----------------" << endl;
407         return EXIT_FAILURE ;
408   }
409
410   if (ret!=-1)
411   {
412         cout << "--------------------------------------------------------" << endl;
413         cout << " pb avec compare entre modulusArray60 et modulusArray90 " << endl;
414         cout << " Les deux tableaux sont differents " << endl;
415         cout << "--------------------------------------------------------" << endl;
416         return EXIT_FAILURE ;
417   }
418   else
419   {
420     cout << " compare entre modulusArray60 et modulusArray90 :  OK" << endl;
421     cout << endl;
422   }
423
424   return EXIT_SUCCESS ;
425 }