TsMatrix.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 /*!
21  \file terralib/unittest/rp/matrix/TsMatrix.cpp
22 
23  \brief A test suit for the Matrix interface.
24 */
25 
26 // TerraLib
27 #include "../Config.h"
28 #include <terralib/rp.h>
29 #include <terralib/common.h>
30 
31 // Boost
32 #define BOOST_TEST_NO_MAIN
33 #include <boost/test/unit_test.hpp>
34 
35 BOOST_AUTO_TEST_SUITE (matrix_tests)
36 
37 BOOST_AUTO_TEST_CASE(generic_tests)
38 {
39  /* Checking basic matrix creation and access */
40 
42  BOOST_CHECK( m1.reset( 2, 2,
44  BOOST_CHECK( ( ! m1.isEmpty() ) );
46 
47  m1( 0 , 0 ) = 0.0;
48  m1( 0 , 1 ) = 1.0;
49  m1( 1 , 0 ) = 2.0;
50  m1( 1 , 1 ) = 3.0;
51 
52  BOOST_CHECK( m1.getLinesNumber() == 2 );
53  BOOST_CHECK( m1.getColumnsNumber() == 2 );
54 
55  BOOST_CHECK( m1( 0 , 0 ) == 0.0 );
56  BOOST_CHECK( m1( 0 , 1 ) == 1.0 );
57  BOOST_CHECK( m1( 1 , 0 ) == 2.0 );
58  BOOST_CHECK( m1( 1 , 1 ) == 3.0 );
59 
60  BOOST_CHECK( m1[ 0 ][ 0 ] == 0.0 );
61  BOOST_CHECK( m1[ 0 ][ 1 ] == 1.0 );
62  BOOST_CHECK( m1[ 1 ][ 0 ] == 2.0 );
63  BOOST_CHECK( m1[ 1 ][ 1 ] == 3.0 );
64 
65  /* Reset test */
66 
67  BOOST_CHECK( m1.reset( 2, 2 ) );
69 
70  m1( 0 , 0 ) = 0.0;
71  m1( 0 , 1 ) = 1.0;
72  m1( 1 , 0 ) = 2.0;
73  m1( 1 , 1 ) = 3.0;
74 
75  BOOST_CHECK( m1.getLinesNumber() == 2 );
76  BOOST_CHECK( m1.getColumnsNumber() == 2 );
77 
78  BOOST_CHECK( m1( 0 , 0 ) == 0.0 );
79  BOOST_CHECK( m1( 0 , 1 ) == 1.0 );
80  BOOST_CHECK( m1( 1 , 0 ) == 2.0 );
81  BOOST_CHECK( m1( 1 , 1 ) == 3.0 );
82 
83  /* Checking copy operator */
84 
86  BOOST_CHECK( m2.isEmpty() );
88 
89  BOOST_CHECK( m2.getLinesNumber() == 0 );
90  BOOST_CHECK( m2.getColumnsNumber() == 0 );
91 
92  m2 = m1;
93 
94  BOOST_CHECK( m2.getLinesNumber() == 2 );
95  BOOST_CHECK( m2.getColumnsNumber() == 2 );
96 
97  BOOST_CHECK( m2( 0 , 0 ) == 0.0 );
98  BOOST_CHECK( m2( 0 , 1 ) == 1.0 );
99  BOOST_CHECK( m2( 1 , 0 ) == 2.0 );
100  BOOST_CHECK( m2( 1 , 1 ) == 3.0 );
101 
102  /* Checking copy constructor */
103 
104  te::rp::Matrix< double > m3( m1 );
105  BOOST_CHECK( m3.getMemPolicy() == te::rp::Matrix< double >::RAMMemPol );
106 
107  BOOST_CHECK( m3.getLinesNumber() == 2 );
108  BOOST_CHECK( m3.getColumnsNumber() == 2 );
109 
110  BOOST_CHECK( m3( 0 , 0 ) == 0.0 );
111  BOOST_CHECK( m3( 0 , 1 ) == 1.0 );
112  BOOST_CHECK( m3( 1 , 0 ) == 2.0 );
113  BOOST_CHECK( m3( 1 , 1 ) == 3.0 );
114 }
115 
116 BOOST_AUTO_TEST_CASE(rAMMemPol_test)
117 {
118  unsigned long int lines = 2;
119  unsigned long int cols = 2;
120 
122  BOOST_CHECK( m1.reset( lines, cols, te::rp::Matrix< double >::RAMMemPol ) );
123 
124  BOOST_CHECK( m1.getMemPolicy() == te::rp::Matrix< double >::RAMMemPol );
125 
126  double counter = 0.0;
127 
128  unsigned int line = 0;
129  unsigned int col = 0;
130 
131  for( line = 0 ; line < lines ; ++line ) {
132  for( col = 0 ; col < cols ; ++col ) {
133  m1( line , col ) = counter;
134 
135  ++counter;
136  }
137  }
138 
139  counter = 0.0;
140 
141  for( line = 0 ; line < lines ; ++line ) {
142  for( col = 0 ; col < cols ; ++col ) {
143  BOOST_CHECK( ( m1( line , col ) == counter ) );
144 
145  ++counter;
146  }
147  }
148 
149  m1.reset();
150 
151  return;
152 }
153 
154 BOOST_AUTO_TEST_CASE(autoMemPol_test)
155 {
156  unsigned long int lines = 3;
157  unsigned long int cols = 3;
158 
160  BOOST_CHECK( m1.reset( te::rp::Matrix< double >::AutoMemPol, lines, cols, 1 ) );
161 
162  BOOST_CHECK( m1.getMemPolicy() == te::rp::Matrix< double >::AutoMemPol );
163 
164  double counter = 0.0;
165 
166  unsigned int line = 0;
167  unsigned int col = 0;
168 
169  for( line = 0 ; line < lines ; ++line ) {
170  for( col = 0 ; col < cols ; ++col ) {
171  m1( line , col ) = counter;
172 
173  ++counter;
174  }
175  }
176 
177  counter = 0.0;
178 
179  for( line = 0 ; line < lines ; ++line ) {
180  for( col = 0 ; col < cols ; ++col ) {
181  BOOST_CHECK( ( m1( line , col ) == counter ) );
182 
183  ++counter;
184  }
185  }
186 
187  m1.reset();
188 
189  return;
190 }
191 
192 BOOST_AUTO_TEST_CASE(diskMemPol_test)
193 {
194  unsigned long int lines = 3;
195  unsigned long int cols = 3;
196 
198  BOOST_CHECK( m1.reset( lines, cols,
200 
201  BOOST_CHECK( m1.getMemPolicy() == te::rp::Matrix< double >::DiskMemPol );
202  BOOST_CHECK( m1.getLinesNumber() == lines );
203  BOOST_CHECK( m1.getColumnsNumber() == cols );
204 
205  unsigned int line = 0;
206  unsigned int col = 0;
207  double counter = 0.0;
208 
209  for( line = 0 ; line < lines ; ++line ) {
210  for( col = 0 ; col < cols ; ++col ) {
211  m1( line , col ) = counter;
212  ++counter;
213  }
214  }
215 
216  counter = 0.0;
217 
218  for( line = 0 ; line < lines ; ++line ) {
219  for( col = 0 ; col < cols ; ++col ) {
220  BOOST_CHECK( ( m1( line , col ) == counter ) );
221  ++counter;
222  }
223  }
224 
225  m1.reset();
226 
227  return;
228 }
229 
230 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(matrix_tests) BOOST_AUTO_TEST_CASE(generic_tests)
Definition: TsMatrix.cpp:35
BOOST_AUTO_TEST_CASE(rAMMemPol_test)
Definition: TsMatrix.cpp:116
MemoryPolicy getMemPolicy() const
Returns the current memory policy.
Definition: Matrix.h:837
unsigned int line
unsigned int getColumnsNumber() const
The number of current matrix columns.
Definition: Matrix.h:798
This file contains include headers for the TerraLib Raster Processing module.
void reset()
Reset (clear) the active instance data.
Definition: Matrix.h:502
This file contains include headers for the TerraLib Common Runtime module.
bool isEmpty() const
Empty Matrix verification.
Definition: Matrix.h:805
unsigned int getLinesNumber() const
The number of current matrix lines.
Definition: Matrix.h:791
unsigned int col