1 |
jgs |
82 |
// $Id$ |
2 |
|
|
/* |
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 |
|
|
#include "escript/Data/DataFactory.h" |
16 |
|
|
#include "escript/Data/Data.h" |
17 |
|
|
|
18 |
|
|
#include "DataFactoryTestCase.h" |
19 |
|
|
|
20 |
|
|
#include <iostream> |
21 |
|
|
|
22 |
|
|
using namespace CppUnitTest; |
23 |
|
|
using namespace escript; |
24 |
|
|
using namespace std; |
25 |
|
|
|
26 |
|
|
void DataFactoryTestCase::setUp() { |
27 |
|
|
// |
28 |
|
|
// This is called before each test is run |
29 |
|
|
|
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
void DataFactoryTestCase::tearDown() { |
33 |
|
|
// |
34 |
|
|
// This is called after each test has been run |
35 |
|
|
|
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
void DataFactoryTestCase::testAll() { |
39 |
|
|
|
40 |
|
|
cout << endl; |
41 |
|
|
|
42 |
|
|
cout << "\tUse DataFactory functions to create some Data objects:" << endl; |
43 |
|
|
|
44 |
|
|
{ |
45 |
|
|
cout << "\tCreate Data (DataConstant) object with Scalar data points." << endl; |
46 |
|
|
Data scalar=Scalar(1.3); |
47 |
|
|
//cout << scalar.toString() << endl; |
48 |
|
|
assert(scalar.isConstant()); |
49 |
|
|
assert(scalar.getDataPointRank()==0); |
50 |
|
|
assert(scalar.getDataPointShape().empty()); |
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
{ |
54 |
|
|
cout << "\tCreate DataExpanded object with Scalar data points." << endl; |
55 |
|
|
Data scalar=Scalar(1.5,FunctionSpace(),true); |
56 |
|
|
//cout << scalar.toString() << endl; |
57 |
|
|
assert(scalar.isExpanded()); |
58 |
|
|
assert(scalar.getDataPointRank()==0); |
59 |
|
|
assert(scalar.getDataPointShape().empty()); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
{ |
63 |
|
|
cout << "\tCreate Data (DataConstant) object with Vector data points." << endl; |
64 |
|
|
Data vector=Vector(1.3); |
65 |
|
|
//cout << vector.toString() << endl; |
66 |
|
|
assert(vector.isConstant()); |
67 |
|
|
assert(vector.getDataPointRank()==1); |
68 |
|
|
assert(vector.getDataPointShape()[0]==1);; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
{ |
72 |
|
|
cout << "\tCreate Data Expanded object with Vector data points." << endl; |
73 |
|
|
Data vector=Vector(1.5,FunctionSpace(),true); |
74 |
|
|
//cout << vector.toString() << endl; |
75 |
|
|
assert(vector.isExpanded()); |
76 |
|
|
assert(vector.getDataPointRank()==1); |
77 |
|
|
assert(vector.getDataPointShape()[0]==1);; |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
{ |
81 |
|
|
cout << "\tCreate Data (DataConstant) object with Tensor data points." << endl; |
82 |
|
|
Data tensor=Tensor(1.3); |
83 |
|
|
//cout << tensor.toString() << endl; |
84 |
|
|
assert(tensor.isConstant()); |
85 |
|
|
assert(tensor.getDataPointRank()==2); |
86 |
|
|
assert(tensor.getDataPointShape()[0]==1);; |
87 |
|
|
assert(tensor.getDataPointShape()[1]==1);; |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
{ |
91 |
|
|
cout << "\tCreate Data Expanded object with Tensor data points." << endl; |
92 |
|
|
Data tensor=Tensor(1.5,FunctionSpace(),true); |
93 |
|
|
//cout << tensor.toString() << endl; |
94 |
|
|
assert(tensor.isExpanded()); |
95 |
|
|
assert(tensor.getDataPointRank()==2); |
96 |
|
|
assert(tensor.getDataPointShape()[0]==1);; |
97 |
|
|
assert(tensor.getDataPointShape()[1]==1);; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
{ |
101 |
|
|
cout << "\tCreate Data (DataConstant) object with Tensor3 data points." << endl; |
102 |
|
|
Data tensor3=Tensor3(1.3); |
103 |
|
|
//cout << tensor3.toString() << endl; |
104 |
|
|
assert(tensor3.isConstant()); |
105 |
|
|
assert(tensor3.getDataPointRank()==3); |
106 |
|
|
assert(tensor3.getDataPointShape()[0]==1);; |
107 |
|
|
assert(tensor3.getDataPointShape()[1]==1);; |
108 |
|
|
assert(tensor3.getDataPointShape()[2]==1);; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
{ |
112 |
|
|
cout << "\tCreate Data Expanded object with Tensor3 data points." << endl; |
113 |
|
|
Data tensor3=Tensor3(1.5,FunctionSpace(),true); |
114 |
|
|
//cout << tensor3.toString() << endl; |
115 |
|
|
assert(tensor3.isExpanded()); |
116 |
|
|
assert(tensor3.getDataPointRank()==3); |
117 |
|
|
assert(tensor3.getDataPointShape()[0]==1);; |
118 |
|
|
assert(tensor3.getDataPointShape()[1]==1);; |
119 |
|
|
assert(tensor3.getDataPointShape()[2]==1);; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
{ |
123 |
|
|
cout << "\tCreate Data (DataConstant) object with Tensor4 data points." << endl; |
124 |
|
|
Data tensor4=Tensor4(1.3); |
125 |
|
|
//cout << tensor4.toString() << endl; |
126 |
|
|
assert(tensor4.isConstant()); |
127 |
|
|
assert(tensor4.getDataPointRank()==4); |
128 |
|
|
assert(tensor4.getDataPointShape()[0]==1);; |
129 |
|
|
assert(tensor4.getDataPointShape()[1]==1);; |
130 |
|
|
assert(tensor4.getDataPointShape()[2]==1);; |
131 |
|
|
assert(tensor4.getDataPointShape()[3]==1);; |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
{ |
135 |
|
|
cout << "\tCreate Data Expanded object with Tensor4 data points." << endl; |
136 |
|
|
Data tensor4=Tensor4(1.5,FunctionSpace(),true); |
137 |
|
|
//cout << tensor4.toString() << endl; |
138 |
|
|
assert(tensor4.isExpanded()); |
139 |
|
|
assert(tensor4.getDataPointRank()==4); |
140 |
|
|
assert(tensor4.getDataPointShape()[0]==1);; |
141 |
|
|
assert(tensor4.getDataPointShape()[1]==1);; |
142 |
|
|
assert(tensor4.getDataPointShape()[2]==1);; |
143 |
|
|
assert(tensor4.getDataPointShape()[3]==1);; |
144 |
|
|
} |
145 |
|
|
|
146 |
|
|
} |
147 |
|
|
|
148 |
|
|
TestSuite* DataFactoryTestCase::suite () |
149 |
|
|
{ |
150 |
|
|
// |
151 |
|
|
// create the suite of tests to perform. |
152 |
|
|
TestSuite *testSuite = new TestSuite ("DataFactoryTestCase"); |
153 |
|
|
|
154 |
|
|
testSuite->addTest (new TestCaller< DataFactoryTestCase>("testAll",&DataFactoryTestCase::testAll)); |
155 |
|
|
return testSuite; |
156 |
|
|
} |
157 |
|
|
|