12 |
* * |
* * |
13 |
***************************************************************************** |
***************************************************************************** |
14 |
*/ |
*/ |
|
#include "EsysException.h" |
|
|
#include "Data.h" |
|
|
#include "FunctionSpace.h" |
|
15 |
|
|
16 |
#include "DataTestCase.h" |
#include "DataTestCase.h" |
17 |
|
|
18 |
|
#include "Data.h" |
19 |
|
#include "FunctionSpace.h" |
20 |
|
#include "EsysException.h" |
21 |
|
|
22 |
#include <iostream> |
#include <iostream> |
23 |
#include <math.h> |
#include <math.h> |
24 |
|
|
302 |
|
|
303 |
cout << endl; |
cout << endl; |
304 |
|
|
305 |
cout << "\tTest DataTagged operations exceptions." << endl; |
cout << "\tTest DataTagged exceptions." << endl; |
306 |
|
|
307 |
Data myData; |
Data myData; |
308 |
DataArrayView myView; |
DataArrayView myView; |
316 |
assert(true); |
assert(true); |
317 |
} |
} |
318 |
|
|
|
/* |
|
319 |
try { |
try { |
320 |
myData.setTaggedValue(0,myView);; |
myData.setTaggedValueFromCPP(0,myView);; |
321 |
assert(false); |
assert(false); |
322 |
} |
} |
323 |
catch (EsysException& e) { |
catch (EsysException& e) { |
324 |
//cout << e.what() << endl; |
//cout << e.what() << endl; |
325 |
assert(true); |
assert(true); |
326 |
} |
} |
|
*/ |
|
327 |
|
|
328 |
} |
} |
329 |
|
|
331 |
|
|
332 |
cout << endl; |
cout << endl; |
333 |
|
|
334 |
cout << "\tCreate a DataTagged object from a DataArrayView" << endl; |
cout << "\tCreate a DataTagged object with a default value only." << endl; |
335 |
|
|
336 |
|
// create tagged data with no tag values just a default |
337 |
|
|
338 |
DataTagged::TagListType keys; |
DataTagged::TagListType keys; |
339 |
|
|
340 |
DataTagged::ValueListType values; |
DataTagged::ValueListType values; |
341 |
|
|
342 |
DataArrayView::ShapeType viewShape; |
DataArrayView::ShapeType viewShape; |
343 |
viewShape.push_back(3); |
viewShape.push_back(3); |
344 |
|
|
345 |
DataArrayView::ValueType viewData(3); |
DataArrayView::ValueType viewData(3); |
346 |
for (int i=0;i<viewShape[0];++i) { |
for (int i=0;i<viewShape[0];++i) { |
347 |
viewData[i]=i; |
viewData[i]=i; |
348 |
} |
} |
349 |
DataArrayView myView(viewData,viewShape); |
DataArrayView myView(viewData,viewShape); |
350 |
|
|
|
// create tagged data with no tag values just a default |
|
351 |
bool expanded=false; |
bool expanded=false; |
352 |
|
|
353 |
Data myData(keys,values,myView,FunctionSpace(),expanded); |
Data myData(keys,values,myView,FunctionSpace(),expanded); |
|
assert(myData.isTagged()); |
|
354 |
|
|
355 |
cout << "\tTest some basic operations" << endl; |
// cout << myData.toString() << endl; |
356 |
|
|
357 |
Data myDataCopy(myData); |
assert(!myData.isEmpty()); |
358 |
myDataCopy.expand(); |
assert(myData.isTagged()); |
359 |
assert(myDataCopy.isExpanded()); |
assert(myData.getTagNumber(0)==1); |
360 |
|
assert(myData.getDataPointRank()==1); |
361 |
|
assert(myData.getLength()==3); |
362 |
|
|
363 |
|
DataArrayView myDataView = myData.getPointDataView(); |
364 |
|
assert(!myDataView.isEmpty()); |
365 |
|
assert(myDataView.getOffset()==0); |
366 |
|
assert(myDataView.getRank()==1); |
367 |
|
assert(myDataView.noValues()==3); |
368 |
|
assert(myDataView.getShape().size()==1); |
369 |
|
assert(myDataView(0)==0.0); |
370 |
|
assert(myDataView(1)==1.0); |
371 |
|
assert(myDataView(2)==2.0); |
372 |
|
|
373 |
|
myDataView = myData.getDataPoint(0,0); |
374 |
|
assert(!myDataView.isEmpty()); |
375 |
|
assert(myDataView.getOffset()==0); |
376 |
|
assert(myDataView.getRank()==1); |
377 |
|
assert(myDataView.noValues()==3); |
378 |
|
assert(myDataView.getShape().size()==1); |
379 |
|
assert(myDataView(0)==0.0); |
380 |
|
assert(myDataView(1)==1.0); |
381 |
|
assert(myDataView(2)==2.0); |
382 |
|
|
383 |
|
double* sampleData=myData.getSampleData(0); |
384 |
|
for (int i=0; i<myDataView.noValues(); i++) { |
385 |
|
assert(sampleData[i]==i); |
386 |
|
} |
387 |
|
// use a non-existent tag so we get a pointer to |
388 |
|
// the first element of the data array |
389 |
|
sampleData=myData.getSampleDataByTag(9); |
390 |
|
for (int i=0; i<myData.getLength(); i++) { |
391 |
|
assert(sampleData[i]==i); |
392 |
|
} |
393 |
|
|
394 |
|
cout << "\tTest setting of a tag and associated value." << endl; |
395 |
|
|
396 |
|
// value for tag "1" |
397 |
|
DataArray eTwo(myView); |
398 |
|
for (int i=0;i<eTwo.getView().getShape()[0];i++) { |
399 |
|
eTwo.getView()(i)=i+2.0; |
400 |
|
} |
401 |
|
|
402 |
|
myData.setTaggedValueFromCPP(1,eTwo.getView()); |
403 |
|
|
404 |
|
assert(myData.getLength()==6); |
405 |
|
|
406 |
|
myDataView = myData.getDataPoint(0,0); |
407 |
|
assert(myDataView==eTwo.getView()); |
408 |
|
assert(!myDataView.isEmpty()); |
409 |
|
assert(myDataView.getOffset()==3); |
410 |
|
assert(myDataView.getRank()==1); |
411 |
|
assert(myDataView.noValues()==3); |
412 |
|
assert(myDataView.getShape().size()==1); |
413 |
|
assert(myDataView(0)==2); |
414 |
|
assert(myDataView(1)==3); |
415 |
|
assert(myDataView(2)==4); |
416 |
|
|
417 |
|
sampleData=myData.getSampleDataByTag(1); |
418 |
|
for (int i=0; i<myDataView.noValues(); i++) { |
419 |
|
assert(sampleData[i]==i+2); |
420 |
|
} |
421 |
|
|
422 |
} |
} |
423 |
|
|