1 |
jgs |
82 |
/* |
2 |
|
|
***************************************************************************** |
3 |
|
|
* * |
4 |
|
|
* COPYRIGHT ACcESS - All Rights Reserved * |
5 |
|
|
* * |
6 |
|
|
* This software is the property of ACcESS. No part of this code * |
7 |
|
|
* may be copied in any form or by any means without the expressed written * |
8 |
|
|
* consent of ACcESS. Copying, use or modification of this software * |
9 |
|
|
* by any unauthorised person is illegal unless that person has a software * |
10 |
|
|
* license agreement with ACcESS. * |
11 |
|
|
* * |
12 |
|
|
***************************************************************************** |
13 |
|
|
*/ |
14 |
|
|
#include "escript/Data/FunctionSpace.h" |
15 |
|
|
#include "escript/Data/DataExpanded.h" |
16 |
|
|
#include "esysUtils/EsysException.h" |
17 |
|
|
#include "DataExpandedTestCase.h" |
18 |
|
|
|
19 |
|
|
#include <iostream> |
20 |
|
|
|
21 |
|
|
using namespace CppUnitTest; |
22 |
|
|
using namespace escript; |
23 |
|
|
using namespace std; |
24 |
|
|
using namespace esysUtils; |
25 |
|
|
|
26 |
|
|
void DataExpandedTestCase::setUp() { |
27 |
|
|
// |
28 |
|
|
// This is called before each test is run |
29 |
|
|
|
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
void DataExpandedTestCase::tearDown() { |
33 |
|
|
// |
34 |
|
|
// This is called after each test has been run |
35 |
|
|
|
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
void DataExpandedTestCase::testReshape() { |
39 |
|
|
|
40 |
|
|
cout << endl; |
41 |
|
|
|
42 |
|
|
// |
43 |
|
|
// Create a scalar pointData |
44 |
|
|
DataArrayView::ShapeType shape; |
45 |
|
|
DataArrayView::ValueType data(DataArrayView::noValues(shape),0); |
46 |
|
|
DataArrayView pointData(data,shape); |
47 |
|
|
|
48 |
|
|
// |
49 |
jgs |
100 |
// assign an arbitrary value |
50 |
jgs |
82 |
pointData()=1.0; |
51 |
|
|
|
52 |
jgs |
100 |
int noDataPointsPerSample=10; |
53 |
|
|
int noSamples=1000; |
54 |
|
|
|
55 |
jgs |
82 |
// |
56 |
jgs |
100 |
// Test construction |
57 |
|
|
cout << "Test DataExpanded constructor." << endl; |
58 |
jgs |
82 |
DataExpanded testData(pointData,FunctionSpace()); |
59 |
|
|
|
60 |
jgs |
100 |
cout << "Test reshapeDataPoint." << endl; |
61 |
jgs |
82 |
shape.push_back(2); |
62 |
|
|
testData.reshapeDataPoint(shape); |
63 |
jgs |
100 |
assert(testData.getPointDataView().getRank() == 1); |
64 |
jgs |
82 |
|
65 |
jgs |
100 |
//for (int i=0;i<noSamples;++i) { |
66 |
|
|
// for (int j=0;j<noDataPointsPerSample;++j) { |
67 |
|
|
// assert(testData.getDataPoint(i,j)(0) == pointData()); |
68 |
|
|
// assert(testData.getDataPoint(i,j)(1) == pointData()); |
69 |
|
|
//} |
70 |
|
|
//} |
71 |
jgs |
82 |
|
72 |
|
|
try { |
73 |
jgs |
100 |
cout << "Test illegal reshape." << endl; |
74 |
jgs |
82 |
testData.reshapeDataPoint(shape); |
75 |
|
|
assert(false); |
76 |
|
|
} |
77 |
|
|
catch (EsysException& e) { |
78 |
jgs |
100 |
cout << e.toString() << endl; |
79 |
jgs |
82 |
assert(true); |
80 |
|
|
} |
81 |
|
|
|
82 |
jgs |
100 |
cout << "Test toString." << endl; |
83 |
|
|
cout << testData.toString() << endl; |
84 |
|
|
|
85 |
|
|
cout << "Test DataExpanded destructor." << endl; |
86 |
|
|
|
87 |
jgs |
82 |
} |
88 |
|
|
|
89 |
jgs |
100 |
void DataExpandedTestCase::testAll() { |
90 |
jgs |
82 |
|
91 |
|
|
cout << endl; |
92 |
|
|
|
93 |
|
|
// |
94 |
jgs |
100 |
// Create a scalar pointData |
95 |
jgs |
82 |
DataArrayView::ShapeType shape; |
96 |
|
|
shape.push_back(3); |
97 |
|
|
DataArrayView::ValueType data(DataArrayView::noValues(shape),0); |
98 |
|
|
DataArrayView pointData(data,shape); |
99 |
|
|
|
100 |
|
|
// |
101 |
jgs |
100 |
// assign an arbitrary value |
102 |
jgs |
82 |
pointData(0)=0.0; |
103 |
|
|
pointData(1)=1.0; |
104 |
|
|
pointData(2)=2.0; |
105 |
|
|
|
106 |
jgs |
100 |
int noDataPointsPerSample=10; |
107 |
|
|
int noSamples=1000; |
108 |
jgs |
82 |
|
109 |
|
|
// |
110 |
jgs |
100 |
// Test construction |
111 |
|
|
cout << "Test DataExpanded constructor." << endl; |
112 |
jgs |
82 |
DataExpanded testData(pointData,FunctionSpace()); |
113 |
|
|
|
114 |
jgs |
100 |
cout << "Test toString." << endl; |
115 |
|
|
cout << testData.toString() << endl; |
116 |
jgs |
82 |
|
117 |
jgs |
100 |
//for (int i=0;i<noSamples;++i) { |
118 |
|
|
//for (int j=0;j<noDataPointsPerSample;++j) { |
119 |
|
|
//assert(testData.getDataPoint(i,j) == pointData); |
120 |
|
|
//} |
121 |
|
|
//} |
122 |
jgs |
82 |
|
123 |
jgs |
100 |
cout << "Test toString." << endl; |
124 |
|
|
cout << testData.toString() << endl; |
125 |
jgs |
82 |
|
126 |
jgs |
100 |
cout << "Test DataExpanded destructor." << endl; |
127 |
jgs |
82 |
|
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
TestSuite* DataExpandedTestCase::suite () |
131 |
|
|
{ |
132 |
|
|
// |
133 |
jgs |
100 |
// create the suite of tests to perform. |
134 |
jgs |
82 |
TestSuite *testSuite = new TestSuite ("DataExpandedTestCase"); |
135 |
jgs |
100 |
|
136 |
jgs |
82 |
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testAll",&DataExpandedTestCase::testAll)); |
137 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testReshape",&DataExpandedTestCase::testReshape)); |
138 |
|
|
return testSuite; |
139 |
|
|
} |
140 |
jgs |
100 |
|
141 |
|
|
|