/[escript]/trunk/escript/test/DataAlgorithmAdapterTestCase.cpp
ViewVC logotype

Annotation of /trunk/escript/test/DataAlgorithmAdapterTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1026 - (hide annotations)
Tue Mar 13 08:25:00 2007 UTC (12 years, 7 months ago) by phornby
File size: 8680 byte(s)
Data.cpp - indefed out the erf & inv. hyperbolics on windows.
DataAlgorithmAdapterTestCase & DataTestCase - Fix the ifndef on _WIN32 & _INTEL_COMPILER
SConstruct - chamges to the PATH so windows can find DLLs.


1 jgs 102 // $Id$
2 jgs 82 /*
3     *****************************************************************************
4     * *
5     * COPYRIGHT ACcESS - All Rights Reserved *
6     * *
7     * This software is the property of ACcESS. No part of this code *
8     * may be copied in any form or by any means without the expressed written *
9     * consent of ACcESS. Copying, use or modification of this software *
10     * by any unauthorised person is illegal unless that person has a software *
11     * license agreement with ACcESS. *
12     * *
13     *****************************************************************************
14     */
15 phornby 1026 #if (defined _WIN32) && (defined __INTEL_COMPILER)
16 woo409 757 #include <mathimf.h>
17     #else
18     #include <math.h>
19     #endif
20 jgs 113
21 robwdcock 670 #include "escript/DataExpanded.h"
22     #include "escript/DataArrayView.h"
23     #include "escript/DataAlgorithm.h"
24 jgs 82 #include "DataAlgorithmAdapterTestCase.h"
25    
26     #include <iostream>
27     #include <algorithm>
28     #include <limits>
29    
30     using namespace CppUnitTest;
31     using namespace std;
32     using namespace escript;
33    
34     void DataAlgorithmAdapterTestCase::setUp() {
35     //
36     // This is called before each test is run
37    
38     }
39    
40     void DataAlgorithmAdapterTestCase::tearDown() {
41     //
42     // This is called after each test has been run
43    
44     }
45    
46     void DataAlgorithmAdapterTestCase::testAll() {
47 jgs 102
48 jgs 82 cout << endl;
49 jgs 102
50 jgs 108 cout << "\tTesting FMax." << endl;
51 jgs 106
52 jgs 108 FMax fmax;
53 gross 713 assert(std::abs(fmax(5,6)-6)<=REL_TOL*6);
54     assert(std::abs(fmax(5,-6)-5)<=REL_TOL*5);
55     assert(std::abs(fmax(0,0)-0)<=REL_TOL*0);
56     assert(std::abs(fmax(15,-96)-15)<=REL_TOL*15);
57 jgs 108
58     DataAlgorithmAdapter<FMax> sup(numeric_limits<double>::max()*-1);
59 jgs 106 sup.resetResult();
60 jgs 108 sup(-1);
61     sup(-2);
62     sup(-14);
63 jgs 106 sup(3);
64 gross 713 assert(std::abs(sup.getResult()-3)<=REL_TOL*3);
65 jgs 102
66     cout << "\tTesting AbsMax." << endl;
67 jgs 108
68     AbsMax absmax;
69 gross 713 assert(std::abs(absmax(5,6)-6)<=REL_TOL*6);
70     assert(std::abs(absmax(5,-6)-6)<=REL_TOL*6);
71     assert(std::abs(absmax(0,0)-0)<=REL_TOL*6);
72     assert(std::abs(absmax(15,-96)-96)<=REL_TOL*6);
73 jgs 108
74 jgs 102 DataAlgorithmAdapter<AbsMax> Lsup(0);
75 jgs 106 Lsup.resetResult();
76 jgs 82 Lsup(-2);
77     Lsup(2);
78     Lsup(5);
79 jgs 102 Lsup(-10);
80 gross 713 assert(std::abs(Lsup.getResult()-10)<=REL_TOL*10);
81 jgs 102
82     cout << "\tTesting FMin." << endl;
83 jgs 108
84     FMin fmin;
85 gross 713 assert(std::abs(fmin(5,6)-5)<=REL_TOL*5);
86     assert(std::abs(fmin(5,-6)-(-6))<=REL_TOL*6);
87     assert(std::abs(fmin(0,0)-0)<=REL_TOL*0);
88     assert(std::abs(fmin(15,-96)-(-96))<=REL_TOL*96);
89 jgs 108
90 jgs 82 DataAlgorithmAdapter<FMin> inf(numeric_limits<double>::max());
91 jgs 106 inf.resetResult();
92 jgs 82 inf(1);
93 jgs 102 inf(12);
94 jgs 82 inf(2);
95 jgs 102 inf(99);
96 gross 713 assert(std::abs(inf.getResult()-1)<=REL_TOL*1);
97 jgs 102
98 jgs 106 cout << "\tTesting Length." << endl;
99 jgs 108
100     Length lngth;
101 gross 713 assert(std::abs(lngth(5,6)-std::sqrt(61.0))<=REL_TOL*std::sqrt(61.0));
102     assert(std::abs(lngth(5,-6)-std::sqrt(61.0))<=REL_TOL*std::sqrt(61.0));
103     assert(std::abs(lngth(0,0)-std::sqrt(0.0))<=REL_TOL*std::sqrt(61.0));
104     assert(std::abs(lngth(15,-96)-std::sqrt(9441.0))<=REL_TOL*std::sqrt(61.0));
105 jgs 108
106 jgs 106 DataAlgorithmAdapter<Length> length(0);
107     length.resetResult();
108     length(2);
109     length(4);
110     length(6);
111     length(8);
112 gross 713 assert(std::abs(length.getResult()-std::sqrt(120.0))<=REL_TOL*std::sqrt(120.0));
113 jgs 106 length.resetResult();
114     length(1.5);
115     length(2.5);
116     length(3.5);
117     length(4.5);
118 gross 713 assert(std::abs(length.getResult()-std::sqrt(41.0))<=REL_TOL*std::sqrt(41.0));
119 jgs 102
120 jgs 106 cout << "\tTesting Trace." << endl;
121 jgs 108
122     Trace trce;
123 gross 713 assert(std::abs(trce(5,6)-11)<=REL_TOL*11);
124     assert(std::abs(trce(5,-6)-(-1))<=REL_TOL*1);
125     assert(std::abs(trce(0,0)-0)<=REL_TOL*0);
126     assert(std::abs(trce(15,-96)-(-81))<=REL_TOL*81);
127 jgs 108
128 jgs 106 DataAlgorithmAdapter<Trace> trace(0);
129     trace.resetResult();
130     trace(1);
131     trace(2);
132     trace(3);
133     trace(4);
134     trace(5);
135 gross 713 assert(std::abs(trace.getResult()-15)<=REL_TOL*15);
136 jgs 106 trace.resetResult();
137     trace(1.5);
138     trace(2.5);
139     trace(3.5);
140     trace(4.5);
141     trace(5.5);
142 gross 713 assert(std::abs(trace.getResult()-17.5)<=REL_TOL*17.5);
143 jgs 106
144 jgs 82 }
145    
146 jgs 113 void DataAlgorithmAdapterTestCase::testAlgorithm() {
147    
148 jgs 561 cout << endl;
149    
150 jgs 113 {
151    
152 jgs 561 cout << "\tTest algorithm on Data objects with a single rank 2 data-point." << endl;
153    
154 jgs 113 // define the shape for the DataArrayView
155     DataArrayView::ShapeType shape;
156     shape.push_back(2);
157     shape.push_back(3);
158    
159     // allocate the data for the DataArrayView
160     DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
161    
162     // construct DataArrayView
163     DataArrayView dataView(dataArray,shape);
164    
165     // assign values to the data point
166     for (int i=0;i<shape[0];i++) {
167     for (int j=0;j<shape[1];j++) {
168     dataView(i,j)=dataView.index(i,j);
169     }
170     }
171    
172     // create a few Data objects from the created DataArrayView
173     DataExpanded dataExp(dataView,FunctionSpace());
174     DataConstant dataCon(dataView,FunctionSpace());
175     DataTagged dataTag(dataCon);
176    
177     // test algorithm on DataExpanded
178 jgs 147 FMin fmin_func;
179 gross 713 assert(std::abs(escript::algorithm(dataExp,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
180 jgs 147 FMax fmax_func;
181 gross 713 assert(std::abs(escript::algorithm(dataExp,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
182 jgs 113
183     // test algorithm on DataTagged
184 gross 713 assert(std::abs(escript::algorithm(dataTag,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
185     assert(std::abs(escript::algorithm(dataTag,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
186 jgs 113
187     // test algorithm on DataConstant
188 gross 713 assert(std::abs(escript::algorithm(dataCon,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
189     assert(std::abs(escript::algorithm(dataCon,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
190 jgs 113
191     }
192    
193     }
194    
195     void DataAlgorithmAdapterTestCase::testDpAlgorithm() {
196    
197 jgs 561 cout << endl;
198    
199 jgs 113 {
200    
201 jgs 561 cout << "\tTest dp_algorithm on Data objects with a single rank 2 data-point." << endl;
202    
203 jgs 113 // define the shapes for the DataArrayViews
204     DataArrayView::ShapeType shape;
205     shape.push_back(2);
206     shape.push_back(3);
207     DataArrayView::ShapeType shape2;
208    
209     // allocate the data for the DataArrayViews
210     DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
211     DataArrayView::ValueType dataArray2(DataArrayView::noValues(shape2),0);
212    
213     // construct DataArrayViews
214     DataArrayView dataView(dataArray,shape);
215     DataArrayView dataView2(dataArray2,shape2);
216    
217     // assign values to the data point
218     for (int i=0;i<shape[0];i++) {
219     for (int j=0;j<shape[1];j++) {
220     dataView(i,j)=dataView.index(i,j);
221     }
222     }
223    
224     // create a few Data objects from the created DataArrayViews
225     DataExpanded dataExp(dataView,FunctionSpace());
226     DataConstant dataCon(dataView,FunctionSpace());
227     DataTagged dataTag(dataCon);
228    
229     // and create Data objects to receive the results of the dp_algorithm calls
230     DataExpanded dataExp2(dataView2,FunctionSpace());
231     DataConstant dataCon2(dataView2,FunctionSpace());
232     DataTagged dataTag2(dataCon2);
233    
234     // test dp_algorithm on DataExpanded
235 jgs 147 FMin fmin_func;
236     escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());
237 gross 713 assert(std::abs(dataExp2.getDataPoint(0,0)()-0)<=REL_TOL*0);
238 jgs 147 FMax fmax_func;
239     escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);
240 gross 713 assert(std::abs(dataExp2.getDataPoint(0,0)()-5)<=REL_TOL*5);
241 jgs 113
242     // test dp_algorithm on DataTagged
243 jgs 147 escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());
244 gross 713 assert(std::abs(dataTag2.getDataPoint(0,0)()-0)<=REL_TOL*0);
245 jgs 147 escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);
246 gross 713 assert(std::abs(dataTag2.getDataPoint(0,0)()-5)<=REL_TOL*5);
247 jgs 113
248     // test dp_algorithm on DataConstant
249 jgs 147 escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());
250 gross 713 assert(std::abs(dataCon2.getDataPoint(0,0)()-0)<=REL_TOL*0);
251 jgs 147 escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);
252 gross 713 assert(std::abs(dataCon2.getDataPoint(0,0)()-5)<=REL_TOL*5);
253 jgs 113
254     }
255    
256     }
257    
258 jgs 82 TestSuite* DataAlgorithmAdapterTestCase::suite ()
259     {
260     //
261     // create the suite of tests to perform.
262     TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");
263    
264     testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));
265 jgs 113 testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testAlgorithm",&DataAlgorithmAdapterTestCase::testAlgorithm));
266     testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testDpAlgorithm",&DataAlgorithmAdapterTestCase::testDpAlgorithm));
267 jgs 82 return testSuite;
268     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26