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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 5 months ago) by ksteube
File size: 3591 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1 ksteube 1312
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 robwdcock 670 #include "escript/DataVector.h"
17 robwdcock 638 #include "esysUtils/EsysException.h"
18 jgs 117
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 jgs 121 vec.resize(1,0,1);
58 jgs 117 assert(vec.size() == 1);
59    
60 jgs 121 vec.resize(1000,0,1);
61 jgs 117 assert(vec.size() == 1000);
62    
63 jgs 121 vec.resize(0,0,1);
64 jgs 117 assert(vec.size() == 0);
65     }
66 jgs 151
67 jgs 117 {
68     cout << "\tCreate and check DataVector objects of various sizes." << endl;
69    
70 jgs 121 DataVector vec1(0,0,1);
71 jgs 117 assert(vec1.size() == 0);
72    
73 jgs 121 DataVector vec2(1,0,1);
74 jgs 117 assert(vec2.size() == 1);
75    
76 jgs 121 DataVector vec3(1000,0,1);
77 jgs 117 assert(vec3.size() == 1000);
78     }
79    
80     {
81     cout << "\tAssign and check various elements to a DataVector." << endl;
82    
83 jgs 121 DataVector vec(1000,0,1);
84 jgs 117
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 jgs 151
102 jgs 117 {
103     cout << "\tCheck DataVector copy constructor." << endl;
104    
105 jgs 121 DataVector vec1(1000,0,1);
106 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
124 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
144 jgs 117
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 jgs 121 DataVector vec1(1000,0,1);
160 jgs 117
161     for (int i=0; i < 1000; i++) {
162     vec1[i] = i;
163     }
164    
165     DataVector vec2;
166    
167     assert(vec1 != vec2);
168     }
169 gross 710 #if defined DOASSERT
170 jgs 117 {
171     cout << "\tCheck DataVector index exception." << endl;
172    
173 jgs 121 DataVector vec(1000,0,1);
174 jgs 117
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 gross 710 #endif
187 jgs 117
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