Matrix_Initialization_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk 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
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 /* Test the accessor operator */
40 #include "Matrix_T.hpp"
41 
42 using namespace std;
43 
44 //Constants
46 {
47  TUDEF("Matrix","Constant Constructor");
48  unsigned badCount = 0;
49 
50  //4 matrices filled with constants
51  gnsstk::Matrix<int> a(2,2,1);
52  gnsstk::Matrix<int> b(8, 2, 3);
53  gnsstk::Matrix<int> c(4, 2, 5);
54  gnsstk::Matrix<int> d(4, 4, 7);
55 
56  for(unsigned i = 0; i < a.rows(); i++)
57  {
58  for(unsigned j = 0; j < a.cols(); j++)
59  {
60  if (1 != a(i,j))
61  {
62  badCount++;
63  }
64  }
65  }
66  TUASSERTE(unsigned,0,badCount);
67  badCount = 0; // Reset error counter
68 
69  for(unsigned i = 0; i < b.rows(); i++)
70  {
71  for(unsigned j = 0; j < b.cols(); j++)
72  {
73  if (3 != b(i,j))
74  {
75  badCount++;
76  }
77  }
78  }
79  TUASSERTE(unsigned,0,badCount);
80  badCount = 0; // Reset error counter
81 
82  for(unsigned i = 0; i < c.rows(); i++)
83  {
84  for(unsigned j = 0; j < c.cols(); j++)
85  {
86  if (5 != c(i,j))
87  {
88  badCount++;
89  }
90  }
91  }
92  TUASSERTE(unsigned,0,badCount);
93  badCount = 0; // Reset error counter
94 
95  for(unsigned i = 0; i < d.rows(); i++)
96  {
97  for(unsigned j = 0; j < d.cols(); j++)
98  {
99  if (7 != d(i,j))
100  {
101  badCount++;
102  }
103  }
104  }
105  TUASSERTE(unsigned,0,badCount);
106  badCount = 0; // Reset error counter
107 
108  return testFramework.countFails();
109 }
110 
111 //-------------------------------------------------------------------------
112 //gnsstk::Vectors -- sort of implicitly tests intialization from array
114 {
115  TUDEF("Matrix","Vector Constructor");
116  unsigned badCount = 0;
117 
118  //Initialize 4 gnsstk::Vectors
120  for(unsigned i = 0; i < 16; i++)
121  v1[i] = i+1;
123  for(unsigned i = 0; i < 16; i++)
124  v2[i] = 16-i;
126  for(unsigned i = 0; i < 4; i++)
127  v3[i] = i+1;
129  for(unsigned i = 0; i < 4; i++)
130  {
131  v4[i] = i+1+4;
132  v4[i+4] = i+1+4;
133  }
134 
135  //Make matrices from gnsstk::Vectors
136  gnsstk::Matrix<int> e(8, 2, v1);
137  gnsstk::Matrix<int> f(4, 4, v2);
138  gnsstk::Matrix<int> g(2, 2, v3);
139  gnsstk::Matrix<int> h(4, 2, v4);
140 
141 
142  for(unsigned i = 0; i < e.rows(); i++)
143  {
144  for(unsigned j = 0; j < e.cols(); j++)
145  {
146  if (v1(i*e.cols()+j) != e(i,j))
147  {
148  badCount++;
149  }
150  }
151  }
152  failDescriptionStream << "Check to see if gnsstk::Matrix set the gnsstk::Vector of values properly into a 8x2 matrix. " << badCount << " of them are set improperly.";
153  failDescriptionString = failDescriptionStream.str();
154  failDescriptionStream.str("");
155  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
156  badCount = 0; // Reset error counter
157 
158  for(unsigned i = 0; i < f.rows(); i++)
159  {
160  for(unsigned j = 0; j < f.cols(); j++)
161  {
162  if (v2(i*f.cols()+j) != f(i,j))
163  {
164  badCount++;
165  }
166  }
167  }
168  failDescriptionStream << "Check to see if gnsstk::Matrix set the gnsstk::Vector of values properly into a 4x4 matrix. " << badCount << " of them are set improperly.";
169  failDescriptionString = failDescriptionStream.str(); failDescriptionStream.str("");
170  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
171  badCount = 0; // Reset error counter
172 
173  for(unsigned i = 0; i < g.rows(); i++)
174  {
175  for(unsigned j = 0; j < g.cols(); j++)
176  {
177  if (v3(i*g.cols()+j) != g(i,j))
178  {
179  badCount++;
180  }
181  }
182  }
183  failDescriptionStream << "Check to see if gnsstk::Matrix set the gnsstk::Vector of values properly into a 2x2 matrix. " << badCount << " of them are set improperly.";
184  failDescriptionString = failDescriptionStream.str(); failDescriptionStream.str("");
185  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
186  badCount = 0; // Reset error counter
187 
188  for(unsigned i = 0; i < h.rows(); i++)
189  {
190  for(unsigned j = 0; j < h.cols(); j++)
191  {
192  if (v4(i*h.cols()+j) != h(i,j))
193  {
194  badCount++;
195  }
196  }
197  }
198  failDescriptionStream << "Check to see if gnsstk::Matrix set the gnsstk::Vector of values properly into a 4x2 matrix. " << badCount << " of them are set improperly.";
199  failDescriptionString = failDescriptionStream.str(); failDescriptionStream.str("");
200  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
201  badCount = 0; // Reset error counter
202 
203  return testFramework.countFails();
204 }
205 
206 
208 {
209  TUDEF("Matrix","Array Constructor");
210 
211  static const double Aarr[] =
212  { 1., -2., 4.,
213  1., -1., 1.,
214  1., 0., 0.,
215  1., -1., 1.,
216  1., -2., 4. };
217  gnsstk::Matrix<double> A(5, 3, Aarr);
218 
219  unsigned arrIdx = 0;
220  for (unsigned row = 0; row < 5; row++)
221  {
222  for (unsigned col = 0; col < 3; col++)
223  {
224  ostringstream failMsgStrm;
225  failMsgStrm << "(" << row << "," << col << ") expected "
226  << Aarr[arrIdx] << ", got " << A(row,col);
227 
228  testFramework.assert_equals(Aarr[arrIdx++], A(row,col), __LINE__,
229  failMsgStrm.str());
230  }
231  }
232 
233  return testFramework.countFails();
234 }
235 
236 
237 int main()
238 {
239  unsigned errorTotal = 0;
240  Matrix_T testClass;
241 
242  errorTotal += testClass.initializeConstantsTest();
243  errorTotal += testClass.initializeVectorsTest();
244  errorTotal += testClass.initializeArrayTest();
245 
246  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
247 
248  return errorTotal; //Return the total number of errors
249 }
Matrix_T::initializeArrayTest
int initializeArrayTest(void)
Definition: Matrix_Initialization_T.cpp:207
main
int main()
Definition: Matrix_Initialization_T.cpp:237
Matrix_T.hpp
Matrix_T::initializeConstantsTest
int initializeConstantsTest(void)
Definition: Matrix_Initialization_T.cpp:45
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
Matrix_T
Definition: Matrix_T.hpp:49
Matrix_T::initializeVectorsTest
int initializeVectorsTest(void)
Definition: Matrix_Initialization_T.cpp:113
gnsstk::Matrix::cols
size_t cols() const
The number of columns in the matrix.
Definition: Matrix.hpp:167
gnsstk::Matrix::rows
size_t rows() const
The number of rows in the matrix.
Definition: Matrix.hpp:165
gnsstk::Matrix
Definition: Matrix.hpp:72
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::Vector< int >
std
Definition: Angle.hpp:142


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39