File: DataVectorTestCase.cpp

package info (click to toggle)
python-escript 5.6-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144,304 kB
  • sloc: python: 592,074; cpp: 136,909; ansic: 18,675; javascript: 9,411; xml: 3,384; sh: 738; makefile: 207
file content (184 lines) | stat: -rw-r--r-- 3,762 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/

#include <escript/DataVector.h>

#include "DataVectorTestCase.h"

#include <escript/EsysException.h>

#include <cppunit/TestCaller.h>
#include <iostream>

using namespace std;
using namespace CppUnit;
using namespace escript;
using namespace escript::DataTypes;


void DataVectorTestCase::testAll()
{
  cout << endl;

  {
    cout << "\tCreate and check an empty DataVector object." << endl;

    RealVectorType vec;
    CPPUNIT_ASSERT(vec.size() == 0);
  }
 
  {
    cout << "\tCheck DataVector resize operation." << endl;

    RealVectorType vec;
    CPPUNIT_ASSERT(vec.size() == 0);

    vec.resize(1,0,1);
    CPPUNIT_ASSERT(vec.size() == 1);

    vec.resize(1000,0,1);
    CPPUNIT_ASSERT(vec.size() == 1000);

    vec.resize(0,0,1);
    CPPUNIT_ASSERT(vec.size() == 0);
  }

  {
    cout << "\tCreate and check DataVector objects of various sizes." << endl;

    RealVectorType vec1(0,0,1);
    CPPUNIT_ASSERT(vec1.size() == 0);

    RealVectorType vec2(1,0,1);
    CPPUNIT_ASSERT(vec2.size() == 1);

    RealVectorType vec3(1000,0,1);
    CPPUNIT_ASSERT(vec3.size() == 1000);
  }

  {
    cout << "\tAssign and check various elements to a DataVector." << endl;

    RealVectorType vec(1000,0,1);

    for (int i=0; i < 1000; i++) {
      vec[i] = i;
    }

    for (int i=0; i < 1000; i++) {
      CPPUNIT_ASSERT(vec[i] == i);
    }

    for (int i=0; i < 1000; i++) {
      vec[i] = i/1000;
    }

    for (int i=0; i < 1000; i++) {
      CPPUNIT_ASSERT(vec[i] == i/1000);
    }
  }

  {
    cout << "\tCheck DataVector copy constructor." << endl;

    RealVectorType vec1(1000,0,1);

    for (int i=0; i < 1000; i++) {
      vec1[i] = i;
    }

    RealVectorType vec2(vec1);

    CPPUNIT_ASSERT(vec1.size() == vec2.size());

    for (int i=0; i < 1000; i++) {
      CPPUNIT_ASSERT(vec2[i] == i);
    }
  }
 
  {
    cout << "\tCheck DataVector = operator." << endl;

    RealVectorType vec1(1000,0,1);

    for (int i=0; i < 1000; i++) {
      vec1[i] = i;
    }

    RealVectorType vec2;

    vec2 = vec1;

    CPPUNIT_ASSERT(vec1.size() == vec2.size());

    for (int i=0; i < 1000; i++) {
      CPPUNIT_ASSERT(vec2[i] == i);
    }
  }
 
  {
    cout << "\tCheck DataVector == operator." << endl;

    RealVectorType vec1(1000,0,1);

    for (int i=0; i < 1000; i++) {
      vec1[i] = i;
    }

    RealVectorType vec2;

    vec2 = vec1;

    CPPUNIT_ASSERT(vec1 == vec2);
  }
 
  {
    cout << "\tCheck DataVector != operator." << endl;

    RealVectorType vec1(1000,0,1);

    for (int i=0; i < 1000; i++) {
      vec1[i] = i;
    }

    RealVectorType vec2;

    CPPUNIT_ASSERT(vec1 != vec2);
  }
/*  
  #if defined DOASSERT
  {
    cout << "\tCheck DataVector index exception." << endl;

    RealVectorType vec(1000,0,1);

    CPPUNIT_ASSERT_THROW( (void) vec[1001],  EsysException);
  }
  #endif
*/
}

TestSuite* DataVectorTestCase::suite()
{
  // create the suite of tests to perform.
  TestSuite *testSuite = new TestSuite("DataVectorTestCase");

  testSuite->addTest(new TestCaller<DataVectorTestCase>(
              "testAll",&DataVectorTestCase::testAll));
  return testSuite;
}