TsArray.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 //TerraLib
21 
22 //...
23 
24 // Unit-Test TerraLib
25 #include "TsArray.h"
26 
28 
30 {
31 // An Array is defined to hold 5 points at the positions (1,1) to (4,4) and (5,1).
32 // After inserting the points, the dimensions size should be 6 in lines and 5 in columns.
33 
35  mypoint1 = new te::gm::Point(10.0, 20.0);
36  mypoint2 = new te::gm::Point(30.0, 20.0);
37  mypoint3 = new te::gm::Point(40.0, 20.0);
38  mypoint4 = new te::gm::Point(50.0, 20.0);
39  mypoint5 = new te::gm::Point(80.0, 80.0);
40 
41  pos.push_back(1); // position (1, 1)
42  pos.push_back(1);
44 
45  pos.clear();
46  pos.push_back(2); // position (2, 2)
47  pos.push_back(2);
49 
50  pos.clear();
51  pos.push_back(3); // position (3, 3)
52  pos.push_back(3);
54 
55  pos.clear();
56  pos.push_back(4); // position (4, 4)
57  pos.push_back(4);
59 
60  pos.clear();
61  pos.push_back(5); // position (5, 1)
62  pos.push_back(1);
64 
65  std::cout << std::endl;
66  std::cout << "Printing array initialized = " << myarray->toString() << std::endl;
67 }
68 
70 {
71  pos.clear();
72  delete myarray;
73 }
74 
76 {
77 //#ifdef TE_COMPILE_ALL
78 
80 
81  CPPUNIT_ASSERT(myarray1->getElementsTypeCode() == te::dt::GEOMETRY_TYPE);
82  CPPUNIT_ASSERT(myarray1->getDimension() == 3);
83  CPPUNIT_ASSERT(myarray1->getTypeCode() == te::dt::ARRAY_TYPE);
84 
85  std::vector<std::size_t> pos;
86 
87  te::gm::Point* mypoint = new te::gm::Point(10.0, 20.0);
88 
90  s->setPoint(0, 10, 20); // lower left
91  s->setPoint(1, 10, 10); // upper left
92  s->setPoint(2, 20, 10); // upper rigth
93  s->setPoint(3, 20, 20); // lower rigth
94  s->setPoint(4, 10, 20); // closing
96  mypolygon->push_back(s);
97 
98  pos.push_back(1); // position (1, 1, 1)
99  pos.push_back(1);
100  pos.push_back(1);
101  myarray1->insert(mypoint, pos);
102  te::gm::Point* p1 = static_cast<te::gm::Point*>(myarray1->getData(pos));
103  CPPUNIT_ASSERT(p1 = mypoint);
104 
105  pos.clear();
106  pos.push_back(1); // position (1, 3, 2)
107  pos.push_back(3);
108  pos.push_back(2);
109  myarray1->insert(mypolygon, pos);
110  te::gm::Polygon* pol1 = static_cast<te::gm::Polygon*>(myarray1->getData(pos));
111  CPPUNIT_ASSERT(pol1 = mypolygon);
112 
113  std::cout <<"Printing array with point and polygon " << myarray1->toString() << std::endl;
114 
115  delete myarray1; //it also deletes mypolygon and mypoint
116 
117 //#endif
118 }
119 
121 {
122 //#ifdef TE_COMPILE_ALL
124 
125  CPPUNIT_ASSERT(b.getDimension() == 3);
126 
127  CPPUNIT_ASSERT(b.getTypeCode() == te::dt::ARRAY_TYPE);
128 
129  CPPUNIT_ASSERT(b.getElementsTypeCode() == te::dt::INT16_TYPE);
130 
131  pos.push_back(1); // position (1, 1, 1)
132  pos.push_back(1);
133  pos.push_back(1);
134 
135  // Inserting INT32 elements in a 1-dimension array
137 
138  CPPUNIT_ASSERT(b.getDimension() == 1);
139 
140  CPPUNIT_ASSERT(b.getTypeCode() == te::dt::ARRAY_TYPE);
141 
142  CPPUNIT_ASSERT(b.getElementsTypeCode() == te::dt::INT32_TYPE);
143 
144  pos.push_back(1); // position (1)
145  //int i = 25;
146  //b1.insert(i, pos); //integer is incompatible with te::dt::AbstractData
147 
148  CPPUNIT_ASSERT_MESSAGE("It is allowed to declare 'te::dt::Array b(3,te::dt::INT32_TYPE)', but it does not allow insert elements of type te::dt::INT32_TYPE", 1 == 2);
149 //#endif
150 }
151 
153 {
154 //#ifdef TE_COMPILE_ALL
155  CPPUNIT_ASSERT(myarray->getElementsTypeCode() == te::dt::GEOMETRY_TYPE);
156 //#endif
157 }
158 
160 {
161 //#ifdef TE_COMPILE_ALL
162  std::cout << std::endl;
163  std::cout << "Dimension 1 size= " << myarray->getDimensionSize(0) << " Dimension 2 size= " << myarray->getDimensionSize(1) << std::endl;
164  CPPUNIT_ASSERT(myarray->getDimensionSize(0) == 6);
165  CPPUNIT_ASSERT(myarray->getDimensionSize(1) == 5);
166  //#endif
167 }
168 
170 {
171 //#ifdef TE_COMPILE_ALL
172  CPPUNIT_ASSERT(myarray->getElementsTypeCode() == te::dt::GEOMETRY_TYPE);
173  CPPUNIT_ASSERT(myarray->getDimension() == 2);
174  CPPUNIT_ASSERT(myarray->getTypeCode() == te::dt::ARRAY_TYPE);
175 
176  std::cout << std::endl;
177  std::cout << "Dimension 1 size= " << myarray->toString() << std::endl;
178 
179  // inserting a new point at a new position (6,1)
180  std::vector<std::size_t> npos;
181 
182  te::gm::Point* newpoint = new te::gm::Point(111.0, 111.0);
183  npos.push_back(6); // position (6, 2)
184  npos.push_back(2);
185  myarray->insert(newpoint, npos);
186 
187  // getting the new point
188  te::gm::Point* p5 = static_cast<te::gm::Point*>(myarray->getData(pos));
189  CPPUNIT_ASSERT(p5 = newpoint);
190 
191  // checking dimension size after insert
192  std::cout << std::endl;
193  std::cout << "After insert: Dimension 1 size= " << myarray->getDimensionSize(0) << " Dimension 2 size= " << myarray->getDimensionSize(1) << std::endl;
194  CPPUNIT_ASSERT(myarray->getDimensionSize(0) == 7);
195  CPPUNIT_ASSERT(myarray->getDimensionSize(1) == 5);
196 //#endif
197 }
198 
200 {
201 //#ifdef TE_COMPILE_ALL
202 
203 // getting first point
204  pos.clear();
205  pos.push_back(1); // position (1, 1)
206  pos.push_back(1);
207  te::gm::Point* p1 = static_cast<te::gm::Point*>(myarray->getData(pos));
208  CPPUNIT_ASSERT(p1 = mypoint1);
209  CPPUNIT_ASSERT(p1->equals(mypoint1));
210 
211 // getting last point
212  pos.clear();
213  pos.push_back(5); // position (5, 1)
214  pos.push_back(1);
215  te::gm::Point* p5 = static_cast<te::gm::Point*>(myarray->getData(pos));
216  CPPUNIT_ASSERT(p5 = mypoint5);
217 
218 //#endif
219 }
220 
222 {
223 //#ifdef TE_COMPILE_ALL
224 
225 // getting first point
226  pos.clear();
227  pos.push_back(1); // position (1, 1)
228  pos.push_back(1);
229 
230  te::gm::Point p1 = static_cast<te::gm::Point&>(myarray->operator[](pos));
231  te::gm::Point p1_alternative = static_cast<te::gm::Point&>((*myarray)[pos]);
232 
233  CPPUNIT_ASSERT(p1.getX() == mypoint1->getX());
234  CPPUNIT_ASSERT(p1.getY() == mypoint1->getY());
235  CPPUNIT_ASSERT(p1.equals(mypoint1));
236 
237  CPPUNIT_ASSERT(p1_alternative.getX() == mypoint1->getX());
238  CPPUNIT_ASSERT(p1_alternative.getY() == mypoint1->getY());
239  CPPUNIT_ASSERT(p1_alternative.equals(mypoint1));
240 //#endif
241 }
242 
244 {
245 //#ifdef TE_COMPILE_ALL
246  te::dt::AbstractData* myclone = myarray->clone();
247  std::cout << std::endl;
248  std::cout << "Cloned Array= " << myclone->toString() << std::endl;
249  CPPUNIT_ASSERT(strcmp((myclone->toString()).c_str(), (myarray->toString()).c_str()) == 0);
250 //#endif
251 }
252 
254 {
255 //#ifdef TE_COMPILE_ALL
256  CPPUNIT_ASSERT(myarray->getTypeCode() == te::dt::ARRAY_TYPE);
257 //#endif
258 }
259 
261 {
262 //#ifdef TE_COMPILE_ALL
263  CPPUNIT_ASSERT_NO_THROW(myarray->toString());
264 //#endif
265 }
void push_back(Curve *ring)
It adds the curve to the curve polygon.
void tcClone()
Test Case: It creates a new clone of the array.
Definition: TsArray.cpp:243
AbstractData * clone() const
It creates a new clone of the array.
Definition: Array.cpp:136
int getElementsTypeCode()
Returns the data type of the elements of the array.
Definition: Array.cpp:96
void tcGetElementsTypeCode()
Test Case: Returns the data type of the elements of the array.
Definition: TsArray.cpp:152
CPPUNIT_TEST_SUITE_REGISTRATION(TsArray)
void tcOperatorBraket()
Test Case: Access data in i index.
Definition: TsArray.cpp:221
te::dt::Array * myarray
Definition: TsArray.h:126
te::gm::Point * mypoint4
Definition: TsArray.h:131
int b
Definition: TsRtree.cpp:32
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
void tcGetTypeCode()
Test Case: Copy Constructor.
Definition: TsArray.cpp:253
virtual std::string toString() const =0
It returns the data value in a string notation.
te::gm::Point * mypoint5
Definition: TsArray.h:132
The type for variable-length multidimensional arrays.
Definition: Array.h:59
const double & getY() const
It returns the Point y-coordinate value.
Definition: Point.h:152
A point with x and y coordinate values.
Definition: Point.h:50
void setPoint(std::size_t i, const double &x, const double &y)
It sets the value of the specified point.
std::size_t getDimension() const
Returns the numbe of dimensions of the array.
Definition: Array.cpp:91
te::gm::Point * mypoint3
Definition: TsArray.h:130
Test suite for the Array class.
std::string toString() const
Return a string with all the data inside array.
Definition: Array.cpp:141
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
void tcGetDimension()
Test Case: Returns the number of dimensions of the array.
Definition: TsArray.cpp:120
te::gm::Point * mypoint2
Definition: TsArray.h:129
void tcGetDimensionSize()
Test Case: Gets the number of elements in the i-th dimension.
Definition: TsArray.cpp:159
void tearDown()
Definition: TsArray.cpp:69
void tcInsert()
Test Case: Inserts data into specified position.
Definition: TsArray.cpp:169
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
te::dt::AbstractData * getData(const std::vector< std::size_t > &i)
Returns data from specified position.
Definition: Array.cpp:122
void tcToString()
Test Case: It returns an string representation of Array.
Definition: TsArray.cpp:260
std::vector< std::size_t > pos
Definition: TsArray.h:127
int getTypeCode() const
Returns the type code for array data: ARRAY_TYPE.
Definition: Array.h:144
te::gm::Point * mypoint1
Definition: TsArray.h:128
void tcArray()
Test Case: Multi-dimensional array constructor.
Definition: TsArray.cpp:75
void setUp()
Definition: TsArray.cpp:29
std::size_t getDimensionSize(std::size_t i) const
Gets the number of elements in the i-th dimension.
Definition: Array.cpp:101
void tcGetData()
Test Case: Returns data from specified position.
Definition: TsArray.cpp:199
Test suite for the Array Class.
Definition: TsArray.h:59
void insert(te::dt::AbstractData *data, const std::vector< std::size_t > &pos)
Inserts data into specified position.
Definition: Array.cpp:108
const double & getX() const
It returns the Point x-coordinate value.
Definition: Point.h:138
virtual bool equals(const Geometry *const rhs, const bool exact=false) const _NOEXCEPT_OP(false)
It returns true if the geometry object is spatially equal to rhs geometry.