1 |
jgs |
117 |
/* |
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 |
robwdcock |
670 |
#include "escript/DataVector.h" |
15 |
robwdcock |
638 |
#include "esysUtils/EsysException.h" |
16 |
jgs |
117 |
|
17 |
|
|
#include "DataVectorTestCase.h" |
18 |
|
|
|
19 |
|
|
#include <iostream> |
20 |
|
|
|
21 |
|
|
using namespace std; |
22 |
|
|
using namespace CppUnitTest; |
23 |
|
|
using namespace escript; |
24 |
|
|
using namespace esysUtils; |
25 |
|
|
|
26 |
|
|
void DataVectorTestCase::setUp() { |
27 |
|
|
// |
28 |
|
|
// This is called before each test is run |
29 |
|
|
|
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
void DataVectorTestCase::tearDown() { |
33 |
|
|
// |
34 |
|
|
// This is called after each test has been run |
35 |
|
|
|
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
void DataVectorTestCase::testAll() { |
39 |
|
|
|
40 |
|
|
cout << endl; |
41 |
|
|
|
42 |
|
|
{ |
43 |
|
|
cout << "\tCreate and check an empty DataVector object." << endl; |
44 |
|
|
|
45 |
|
|
DataVector vec; |
46 |
|
|
assert(vec.size() == 0); |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
{ |
50 |
|
|
cout << "\tCheck DataVector resize operation." << endl; |
51 |
|
|
|
52 |
|
|
DataVector vec; |
53 |
|
|
assert(vec.size() == 0); |
54 |
|
|
|
55 |
jgs |
121 |
vec.resize(1,0,1); |
56 |
jgs |
117 |
assert(vec.size() == 1); |
57 |
|
|
|
58 |
jgs |
121 |
vec.resize(1000,0,1); |
59 |
jgs |
117 |
assert(vec.size() == 1000); |
60 |
|
|
|
61 |
jgs |
121 |
vec.resize(0,0,1); |
62 |
jgs |
117 |
assert(vec.size() == 0); |
63 |
|
|
} |
64 |
jgs |
151 |
|
65 |
jgs |
117 |
{ |
66 |
|
|
cout << "\tCreate and check DataVector objects of various sizes." << endl; |
67 |
|
|
|
68 |
jgs |
121 |
DataVector vec1(0,0,1); |
69 |
jgs |
117 |
assert(vec1.size() == 0); |
70 |
|
|
|
71 |
jgs |
121 |
DataVector vec2(1,0,1); |
72 |
jgs |
117 |
assert(vec2.size() == 1); |
73 |
|
|
|
74 |
jgs |
121 |
DataVector vec3(1000,0,1); |
75 |
jgs |
117 |
assert(vec3.size() == 1000); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
{ |
79 |
|
|
cout << "\tAssign and check various elements to a DataVector." << endl; |
80 |
|
|
|
81 |
jgs |
121 |
DataVector vec(1000,0,1); |
82 |
jgs |
117 |
|
83 |
|
|
for (int i=0; i < 1000; i++) { |
84 |
|
|
vec[i] = i; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
for (int i=0; i < 1000; i++) { |
88 |
|
|
assert(vec[i] == i); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
for (int i=0; i < 1000; i++) { |
92 |
|
|
vec[i] = i/1000; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
for (int i=0; i < 1000; i++) { |
96 |
|
|
assert(vec[i] == i/1000); |
97 |
|
|
} |
98 |
|
|
} |
99 |
jgs |
151 |
|
100 |
jgs |
117 |
{ |
101 |
|
|
cout << "\tCheck DataVector copy constructor." << endl; |
102 |
|
|
|
103 |
jgs |
121 |
DataVector vec1(1000,0,1); |
104 |
jgs |
117 |
|
105 |
|
|
for (int i=0; i < 1000; i++) { |
106 |
|
|
vec1[i] = i; |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
DataVector vec2(vec1); |
110 |
|
|
|
111 |
|
|
assert(vec1.size() == vec2.size()); |
112 |
|
|
|
113 |
|
|
for (int i=0; i < 1000; i++) { |
114 |
|
|
assert(vec2[i] == i); |
115 |
|
|
} |
116 |
|
|
} |
117 |
|
|
|
118 |
|
|
{ |
119 |
|
|
cout << "\tCheck DataVector = operator." << endl; |
120 |
|
|
|
121 |
jgs |
121 |
DataVector vec1(1000,0,1); |
122 |
jgs |
117 |
|
123 |
|
|
for (int i=0; i < 1000; i++) { |
124 |
|
|
vec1[i] = i; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
DataVector vec2; |
128 |
|
|
|
129 |
|
|
vec2 = vec1; |
130 |
|
|
|
131 |
|
|
assert(vec1.size() == vec2.size()); |
132 |
|
|
|
133 |
|
|
for (int i=0; i < 1000; i++) { |
134 |
|
|
assert(vec2[i] == i); |
135 |
|
|
} |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
{ |
139 |
|
|
cout << "\tCheck DataVector == operator." << endl; |
140 |
|
|
|
141 |
jgs |
121 |
DataVector vec1(1000,0,1); |
142 |
jgs |
117 |
|
143 |
|
|
for (int i=0; i < 1000; i++) { |
144 |
|
|
vec1[i] = i; |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
DataVector vec2; |
148 |
|
|
|
149 |
|
|
vec2 = vec1; |
150 |
|
|
|
151 |
|
|
assert(vec1 == vec2); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
{ |
155 |
|
|
cout << "\tCheck DataVector != operator." << endl; |
156 |
|
|
|
157 |
jgs |
121 |
DataVector vec1(1000,0,1); |
158 |
jgs |
117 |
|
159 |
|
|
for (int i=0; i < 1000; i++) { |
160 |
|
|
vec1[i] = i; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
DataVector vec2; |
164 |
|
|
|
165 |
|
|
assert(vec1 != vec2); |
166 |
|
|
} |
167 |
gross |
710 |
#if defined DOASSERT |
168 |
jgs |
117 |
{ |
169 |
|
|
cout << "\tCheck DataVector index exception." << endl; |
170 |
|
|
|
171 |
jgs |
121 |
DataVector vec(1000,0,1); |
172 |
jgs |
117 |
|
173 |
|
|
try { |
174 |
|
|
double x = vec[1001]; |
175 |
|
|
assert(false); |
176 |
|
|
} |
177 |
|
|
|
178 |
|
|
catch (EsysException& e) { |
179 |
|
|
//cout << e.toString() << endl; |
180 |
|
|
assert(true); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
} |
184 |
gross |
710 |
#endif |
185 |
jgs |
117 |
|
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
TestSuite* DataVectorTestCase::suite () |
189 |
|
|
{ |
190 |
|
|
// |
191 |
|
|
// create the suite of tests to perform. |
192 |
|
|
TestSuite *testSuite = new TestSuite ("DataVectorTestCase"); |
193 |
|
|
|
194 |
|
|
testSuite->addTest (new TestCaller< DataVectorTestCase>("testAll",&DataVectorTestCase::testAll)); |
195 |
|
|
return testSuite; |
196 |
|
|
} |
197 |
|
|
|