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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (show annotations)
Fri Jan 11 07:45:26 2008 UTC (11 years, 9 months ago) by trankine
File size: 3591 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "escript/DataVector.h"
17 #include "esysUtils/EsysException.h"
18
19 #include "DataVectorTestCase.h"
20
21 #include <iostream>
22
23 using namespace std;
24 using namespace CppUnitTest;
25 using namespace escript;
26 using namespace esysUtils;
27
28 void DataVectorTestCase::setUp() {
29 //
30 // This is called before each test is run
31
32 }
33
34 void DataVectorTestCase::tearDown() {
35 //
36 // This is called after each test has been run
37
38 }
39
40 void DataVectorTestCase::testAll() {
41
42 cout << endl;
43
44 {
45 cout << "\tCreate and check an empty DataVector object." << endl;
46
47 DataVector vec;
48 assert(vec.size() == 0);
49 }
50
51 {
52 cout << "\tCheck DataVector resize operation." << endl;
53
54 DataVector vec;
55 assert(vec.size() == 0);
56
57 vec.resize(1,0,1);
58 assert(vec.size() == 1);
59
60 vec.resize(1000,0,1);
61 assert(vec.size() == 1000);
62
63 vec.resize(0,0,1);
64 assert(vec.size() == 0);
65 }
66
67 {
68 cout << "\tCreate and check DataVector objects of various sizes." << endl;
69
70 DataVector vec1(0,0,1);
71 assert(vec1.size() == 0);
72
73 DataVector vec2(1,0,1);
74 assert(vec2.size() == 1);
75
76 DataVector vec3(1000,0,1);
77 assert(vec3.size() == 1000);
78 }
79
80 {
81 cout << "\tAssign and check various elements to a DataVector." << endl;
82
83 DataVector vec(1000,0,1);
84
85 for (int i=0; i < 1000; i++) {
86 vec[i] = i;
87 }
88
89 for (int i=0; i < 1000; i++) {
90 assert(vec[i] == i);
91 }
92
93 for (int i=0; i < 1000; i++) {
94 vec[i] = i/1000;
95 }
96
97 for (int i=0; i < 1000; i++) {
98 assert(vec[i] == i/1000);
99 }
100 }
101
102 {
103 cout << "\tCheck DataVector copy constructor." << endl;
104
105 DataVector vec1(1000,0,1);
106
107 for (int i=0; i < 1000; i++) {
108 vec1[i] = i;
109 }
110
111 DataVector vec2(vec1);
112
113 assert(vec1.size() == vec2.size());
114
115 for (int i=0; i < 1000; i++) {
116 assert(vec2[i] == i);
117 }
118 }
119
120 {
121 cout << "\tCheck DataVector = operator." << endl;
122
123 DataVector vec1(1000,0,1);
124
125 for (int i=0; i < 1000; i++) {
126 vec1[i] = i;
127 }
128
129 DataVector vec2;
130
131 vec2 = vec1;
132
133 assert(vec1.size() == vec2.size());
134
135 for (int i=0; i < 1000; i++) {
136 assert(vec2[i] == i);
137 }
138 }
139
140 {
141 cout << "\tCheck DataVector == operator." << endl;
142
143 DataVector vec1(1000,0,1);
144
145 for (int i=0; i < 1000; i++) {
146 vec1[i] = i;
147 }
148
149 DataVector vec2;
150
151 vec2 = vec1;
152
153 assert(vec1 == vec2);
154 }
155
156 {
157 cout << "\tCheck DataVector != operator." << endl;
158
159 DataVector vec1(1000,0,1);
160
161 for (int i=0; i < 1000; i++) {
162 vec1[i] = i;
163 }
164
165 DataVector vec2;
166
167 assert(vec1 != vec2);
168 }
169 #if defined DOASSERT
170 {
171 cout << "\tCheck DataVector index exception." << endl;
172
173 DataVector vec(1000,0,1);
174
175 try {
176 double x = vec[1001];
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