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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (hide annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 3 months ago) by ksteube
File size: 3556 byte(s)
Copyright updated in all files

1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 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 ksteube 1312
14 ksteube 1811
15 robwdcock 670 #include "escript/DataVector.h"
16 robwdcock 638 #include "esysUtils/EsysException.h"
17 jgs 117
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 jgs 121 vec.resize(1,0,1);
57 jgs 117 assert(vec.size() == 1);
58    
59 jgs 121 vec.resize(1000,0,1);
60 jgs 117 assert(vec.size() == 1000);
61    
62 jgs 121 vec.resize(0,0,1);
63 jgs 117 assert(vec.size() == 0);
64     }
65 jgs 151
66 jgs 117 {
67     cout << "\tCreate and check DataVector objects of various sizes." << endl;
68    
69 jgs 121 DataVector vec1(0,0,1);
70 jgs 117 assert(vec1.size() == 0);
71    
72 jgs 121 DataVector vec2(1,0,1);
73 jgs 117 assert(vec2.size() == 1);
74    
75 jgs 121 DataVector vec3(1000,0,1);
76 jgs 117 assert(vec3.size() == 1000);
77     }
78    
79     {
80     cout << "\tAssign and check various elements to a DataVector." << endl;
81    
82 jgs 121 DataVector vec(1000,0,1);
83 jgs 117
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 jgs 151
101 jgs 117 {
102     cout << "\tCheck DataVector copy constructor." << endl;
103    
104 jgs 121 DataVector vec1(1000,0,1);
105 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
123 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
143 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
159 jgs 117
160     for (int i=0; i < 1000; i++) {
161     vec1[i] = i;
162     }
163    
164     DataVector vec2;
165    
166     assert(vec1 != vec2);
167     }
168 gross 710 #if defined DOASSERT
169 jgs 117 {
170     cout << "\tCheck DataVector index exception." << endl;
171    
172 jgs 121 DataVector vec(1000,0,1);
173 jgs 117
174     try {
175     double x = vec[1001];
176     assert(false);
177     }
178    
179     catch (EsysException& e) {
180     //cout << e.toString() << endl;
181     assert(true);
182     }
183    
184     }
185 gross 710 #endif
186 jgs 117
187     }
188    
189     TestSuite* DataVectorTestCase::suite ()
190     {
191     //
192     // create the suite of tests to perform.
193     TestSuite *testSuite = new TestSuite ("DataVectorTestCase");
194    
195     testSuite->addTest (new TestCaller< DataVectorTestCase>("testAll",&DataVectorTestCase::testAll));
196     return testSuite;
197     }
198    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26