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

Contents of /trunk/escript/test/DataVectorTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (9 years, 9 months ago) by jfenwick
File size: 3553 byte(s)
Don't panic.
Updating copyright stamps

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26