Matrix_Operators_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 #include "Matrix_T.hpp"
40 
41 /* Test the add/subtract and set operators */
43 {
44  gnsstk::TestUtil testFramework("Matrix","Operators",__FILE__,__LINE__);
45  std::string failMesg;
46  int badCount = 0;
47 
49  for(int i = 0; i < 16; i++) v1[i] = i+1;
51  for(int i = 0; i < 16; i++) v2[i] = 16-i;
53  for(int i = 0; i < 4; i++) v3[i] = i+1;
55  for(int i = 0; i < 4; i++) {v4[i] = i+1+4; v4[i+4] = i+1+4;}
56 
57  gnsstk::Matrix<int> a(2,2,1);
58  gnsstk::Matrix<int> b(8, 2, 3);
59  gnsstk::Matrix<int> c(4, 2, 5);
60  gnsstk::Matrix<int> d(4, 4, 7);
61  gnsstk::Matrix<int> e(8, 2, v1);
62  gnsstk::Matrix<int> f(4, 4, v2);
63  gnsstk::Matrix<int> g(2, 2, v3);
64  gnsstk::Matrix<int> h(4, 2, v4);
65 
66 //--------------Matrix_operatorTest_1 - Does 2x2 additon function as expected?
67  a += g; // 2x2 addition
68  for(int i = 0; i < a.rows(); i++)
69  for(int j = 0; j < a.cols(); j++)
70  if (v3(i*g.cols()+j)+1 != a(i,j)) {badCount++;}
71  failDescriptionStream << "Check to see if addition between two 2x2 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
73  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
74  badCount = 0; // Reset error counter;
75  a -= g; // 2x2 reset a
76 
77 //--------------Matrix_operatorTest_2 - Does 8x2 subtraction work as expected?
78  b -= e; // 8x2 subtraction
79  for(int i = 0; i < b.rows(); i++)
80  for(int j = 0; j < b.cols(); j++)
81  //cout << b(i,j) << " " << 3-(1+i+j*8) << endl;
82  if (3-v1(i*e.cols()+j) != b(i,j)) {badCount++;}
83  failDescriptionStream << "Check to see if subtraction between two 8x2 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
85  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
86  badCount = 0; // Reset error counter;
87  b += e; // 8x2 reset b
88 
89 //--------------Matrix_operatorTest_3 - Does 4x2 subtraction work as expected?
90  c -= h; // 4x2 subtraction
91  for(int i = 0; i < c.rows(); i++)
92  for(int j = 0; j < c.cols(); j++)
93  //cout << c(i,j) << " " << 5-(5.+i) << endl;
94  if (5-v4(i*h.cols()+j) != c(i,j)) {badCount++;}
95  failDescriptionStream << "Check to see if subtraction between two 4x2 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
97  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
98  badCount = 0; // Reset error counter;
99  c += h; // 4x2 reset c
100 
101 //--------------Matrix_operatorTest_4 - Does 4x4 addition work as expected?
102  d += f; // 4x4 addition
103  for(int i = 0; i < d.rows(); i++)
104  for(int j = 0; j < d.cols(); j++)
105  //cout << d(i,j) << " " << 16-i-4*j+7 << endl;
106  if (v2(i*f.cols()+j)+7 != d(i,j)) {badCount++;}
107  failDescriptionStream << "Check to see if addition between two 4x4 gnsstk::Matrix objects works. " << badCount << " of the elements are incorrect.";
109  testFramework.assert(badCount==0, failDescriptionString, __LINE__);
110  badCount = 0; // Reset error counter
111  d -= f; // 4x4 reset d
112 
113  return testFramework.countFails();
114 }
115 
116 int main()
117 {
118  int check, errorCounter = 0;
119  Matrix_T testClass;
120 
121  check = testClass.operatorTest();
122  errorCounter += check;
123 
124  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
125 
126  return errorCounter; //Return the total number of errors
127 }
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
Matrix_T.hpp
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
Matrix_T::failDescriptionStream
std::stringstream failDescriptionStream
Definition: Matrix_T.hpp:143
Matrix_T
Definition: Matrix_T.hpp:49
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
Matrix_T::failDescriptionString
std::string failDescriptionString
Definition: Matrix_T.hpp:144
Matrix_T::failMesg
std::string failMesg
Definition: Matrix_T.hpp:145
main
int main()
Definition: Matrix_Operators_T.cpp:116
gnsstk::Matrix
Definition: Matrix.hpp:72
gnsstk::Vector< int >
Matrix_T::operatorTest
int operatorTest(void)
Definition: Matrix_Operators_T.cpp:42
gnsstk::TestUtil
Definition: TestUtil.hpp:265


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