Triple_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 "Triple.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 #include <cmath>
43 using namespace std;
44 using namespace gnsstk;
46 {
47  public:
48  TripleTest(){eps = 1e-12;}// Default Constructor, set the precision value
49  ~TripleTest() {} // Default Desructor
50  double eps;// Shouldn't this be private?
51 
52  /* Test to initialize and set Triple objects. */
53  int setTest()
54  {
55  TestUtil testFramework( "Triple", "Set", __FILE__, __LINE__ );
56  std::string failMesg;
57 
58  Triple test, test2(1,2,3), test3(test2);
59  test = valarray<double>(3);
60 
61  //std::cout << "The Average is: " << test.Average() << std::endl;
62 
63  failMesg = "Was tje Triple created correctly?";
64  testFramework.assert((test.size() == 3) && (test2.size() == 3) && (test3.size() == 3), failMesg, __LINE__);
65 
66  return testFramework.countFails();
67  }
68  /* Verify the dot product calculation. */
69  int dotTest()
70  {
71  TestUtil testFramework( "Triple", "Dot", __FILE__, __LINE__ );
72  std::string failMesg;
73 
74  Triple test(1,2,3),test2(2,2,2);
75  double result;
76 
77  result = test.dot(test2);
78 
79  //std::cout << "The dot product is: " << result << std::endl;
80 
81  failMesg = "Did the dot method function properly?";
82  testFramework.assert(result == 12, failMesg, __LINE__);
83 
84  return testFramework.countFails();
85  }
86  /* Verify the cross product calculation. */
87  int crossTest()
88  {
89  TestUtil testFramework( "Triple", "Cross", __FILE__, __LINE__ );
90  std::string failMesg;
91 
92  Triple test(1,2,3), test2(2,2,2), test3;
93 
94  test3 = test.cross(test2);
95 
96  //std::cout << "The cross product is: " << test3 << std::endl;
97 
98  failMesg = "Did the method function properly?";
99  testFramework.assert((test3[0] == -2) && (test3[1] == 4) && (test3[2] == -2), failMesg, __LINE__);
100  return testFramework.countFails();
101  }
102  /* Verify the magnitude calculation.
103  Note this presumes the L2 (Euclidian) norm of the vector. */
104  int magTest()
105  {
106  TestUtil testFramework( "Triple", "Mag", __FILE__, __LINE__ );
107  std::string failMesg;
108 
109  Triple test(3,4,0);
110 
111  failMesg = "Did the calculation return the correct values?";
112  testFramework.assert(test.mag() == 5, failMesg, __LINE__);
113 
114  test[0] = 0; test[1] = 0; test[2] = -2;
115 
116  failMesg = "Did the calculation return the correct values?";
117  testFramework.assert(test.mag() == 2, failMesg, __LINE__);
118 
119  return testFramework.countFails();
120  }
121  /* Verify the unit vector calculation. */
123  {
124  TestUtil testFramework( "Triple", "unitVector", __FILE__, __LINE__ );
125  std::string failMesg;
126 
127  Triple test(3,4,0),test2;
128  test2 = test.unitVector();
129 
130  failMesg = "Did the calculation return the correct values?";
131  testFramework.assert( (fabs(test2[0] - 3.0/5.0)*5.0/3.0 < eps) && (fabs(test2[1] - 4.0/5.0)*5.0/4.0 < eps) && (fabs(test2[2]) < eps) , failMesg, __LINE__);
132 
133  test[0] = 0; test[1] = 0; test[2] = -2;
134  test2 = test.unitVector();
135 
136  failMesg = "Did the calculation return the correct values?";
137  testFramework.assert((test2[0] == 0) && (test2[1] == 0) && (test2[2] == -1.0), failMesg, __LINE__);
138 
139  return testFramework.countFails();
140  }
141  /* Verify the cosine of the angle between two triples calculation. */
143  {
144  TestUtil testFramework( "Triple", "cosVector", __FILE__, __LINE__ );
145  std::string failMesg;
146 
147  Triple test(1,0,1),test2(-1,0,-1);
148 
149  failMesg = "Is the computed cosine value correct?";
150  testFramework.assert(fabs(test.cosVector(test2) + 1) < eps, failMesg, __LINE__);
151 
152  test2[0] = 0; test2[1] = 1; test2[2] = 0;
153 
154  failMesg = "Is the computed cosine value correct?";
155  testFramework.assert(fabs(test.cosVector(test2)) < eps, failMesg, __LINE__);
156 
157  test[0] = 1; test[1] = 0; test[2] = 0;
158  test2[0] = 1; test2[1] = 1; test2[2] = 0;
159 
160  failMesg = "Is the computed cosine value correct?";
161  testFramework.assert(fabs(test.cosVector(test2) - sqrt(2.0)/2.0) < eps, failMesg, __LINE__);
162 
163  return testFramework.countFails();
164  }
165  /* Verify the slant range calculation */
167  {
168  TestUtil testFramework( "Triple", "slantRange", __FILE__, __LINE__ );
169  std::string failMesg;
170 
171  Triple test(4,6,3),test2(1,2,3);
172 
173  failMesg = "Was the slant range calculation computed correctly?";
174  testFramework.assert(fabs(test.slantRange(test2)- 5) < eps, failMesg, __LINE__);
175 
176  test[0] = 11; test[1] = -12; test[2] = 10;
177  test2[0] = 1; test2[1] = 2; test2[2] = 3;
178 
179  failMesg = "Was the slant range calculation computed correctly?";
180  testFramework.assert(fabs(test.slantRange(test2) - sqrt(345.0)) < eps, failMesg, __LINE__);
181 
182  return testFramework.countFails();
183  }
184  /* Verify the elevation angle calculation */
186  {
187  TestUtil testFramework( "Triple", "elvAngle", __FILE__, __LINE__ );
188  std::string failMesg;
189 
190  Triple test(1,0,0),test2(0,-1,0);
191  double result;
192 
193  failMesg = "Was the elevation angle calculation computed correctly?";
194  testFramework.assert(fabs(test.elvAngle(test2) + 45) < eps, failMesg, __LINE__);
195 
196  test[0] = 11; test[1] = -12; test[2] = 10;
197  test2[0] = 1; test2[1] = 2; test2[2] = 3;
198  result = acos(-348.0/(sqrt(365.0)*sqrt(345.0)))*180.0/(4.0*atan(1.0));
199  result = 90 - result;
200 
201  failMesg = "Was the elevation angle calculation computed correctly?";
202  testFramework.assert(fabs(test.elvAngle(test2) - result) < eps, failMesg, __LINE__);
203 
204  test[0] = 1; test[1] = 1; test[2] = 1;
205  test2[0] = 1; test2[1] = 0; test2[2] = 0;
206 
207  failMesg = "Was the elevation angle calculation computed correctly?";
208  testFramework.assert(fabs(test.elvAngle(test2) - (90 - acos(-2.0/sqrt(6.0))*180.0/(4.0*atan(1.0)))) < eps, failMesg, __LINE__);
209 
210  return testFramework.countFails();
211  }
212  /* Verify the azimuthal angle calculation
213  Uses relative error to check the number of correct digits */
215  {
216  TestUtil testFramework( "Triple", "azAngle", __FILE__, __LINE__ );
217  std::string failMesg;
218 
219  Triple test(1,1,1),test2(-1,1,1);
220 
221  failMesg = "Was the azimutal angle calculation computed correctly?";
222  testFramework.assert(fabs(test.azAngle(test2) - 60) < eps, failMesg, __LINE__);
223 
224  test[0] = 11; test[1] = -12; test[2] = 10;
225  test2[0] = 1; test2[1] = 2; test2[2] = 3;
226 
227  failMesg = "Was the azimutal angle calculation computed correctly?";
228  testFramework.assert(fabs(test.azAngle(test2) - 35.0779447169289) < eps, failMesg, __LINE__);
229 
230  test[0] = 1; test[1] = 0; test[2] = 0;
231  test2[0] = 0; test2[1] = 1; test2[2] = 0;
232 
233  failMesg = "Was the azimutal angle calculation computed correctly?";
234  testFramework.assert(fabs(test.azAngle(test2) - 90)/90 < eps, failMesg, __LINE__);
235 
236  test[0] = 1; test[1] = -1; test[2] = 1;
237  test2[0] = 1; test2[1] = 1; test2[2] = 1;
238 
239  failMesg = "Was the azimutal angle calculation computed correctly?";
240  testFramework.assert(fabs(test.azAngle(test2) - 60)/60 < eps, failMesg, __LINE__);
241 
242 
243 /* Special case: Using the origin as the point in which to find the azimuthal angle should ALWAYS cause test for p1+p2 != 0 to fail (see Triple.cpp).
244  This next test is to ensure that the error is indeed thrown when it should. */
245 
246  test2[0] = 0; test2[1] = 0; test2[2] = 0;
247  failMesg = "[testing] Triple.azAngle() at origin, [expected] exception gnsstk::Exception, [actual] threw no exception";
248  try {test.azAngle(test2); testFramework.assert(false, failMesg, __LINE__);}
249  catch (Exception& e) {testFramework.assert(true, failMesg, __LINE__);}
250  catch (...)
251  {
252  failMesg = "[testing] Triple.azAngle() at origin, [expected] exception gnsstk::Exception, [actual] threw different exception";
253  testFramework.assert(false, failMesg, __LINE__);
254  }
255 
256 /* Special case: Using the south, (0,0,-1), direction as the position from which to find the azimuthal angle should also cause the initial check to
257  get the angles to fail. */
258 
259  test[0] = 0; test[1] = 0; test[2] = -1;
260  test2[0] = 1; test2[1] = 1; test2[2] = 1;
261  failMesg = "[testing] Triple.azAngle() at origin and due south, [expected] exception gnsstk::Exception, [actual] threw no exception";
262  try {test.azAngle(test2); testFramework.assert(false, failMesg, __LINE__);}
263  catch (Exception& e) {testFramework.assert(true, failMesg, __LINE__);}
264  catch (...)
265  {
266  failMesg = "[testing] Triple.azAngle() at origin and due south, [expected] exception gnsstk::Exception, [actual] threw no exception";
267  testFramework.assert(false, failMesg, __LINE__);
268  }
269 
270  return testFramework.countFails();
271  }
272 
273  };
274 
275 
276 int main() //Main function to initialize and run all tests above
277 {
278  int check, errorCounter = 0;
279  TripleTest testClass;
280 
281  check = testClass.setTest();
282  errorCounter += check;
283 
284  check = testClass.dotTest();
285  errorCounter += check;
286 
287  check = testClass.crossTest();
288  errorCounter += check;
289 
290  check = testClass.magTest();
291  errorCounter += check;
292 
293  check = testClass.unitVectorTest();
294  errorCounter += check;
295 
296  check = testClass.cosVectorTest();
297  errorCounter += check;
298 
299  check = testClass.slantRangeTest();
300  errorCounter += check;
301 
302  check = testClass.elvAngleTest();
303  errorCounter += check;
304 
305  check = testClass.azAngleTest();
306  errorCounter += check;
307 
308  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
309 
310  return errorCounter; //Return the total number of errors
311 }
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
TripleTest::~TripleTest
~TripleTest()
Definition: Triple_T.cpp:49
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
gnsstk::Triple::size
size_t size(void) const
Return the size of this object.
Definition: Triple.hpp:240
TripleTest::eps
double eps
Definition: Triple_T.cpp:50
TripleTest::slantRangeTest
int slantRangeTest()
Definition: Triple_T.cpp:166
main
int main()
Definition: Triple_T.cpp:276
TripleTest::dotTest
int dotTest()
Definition: Triple_T.cpp:69
TripleTest::cosVectorTest
int cosVectorTest()
Definition: Triple_T.cpp:142
gnsstk::Triple
Definition: Triple.hpp:68
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::Triple::unitVector
Triple unitVector() const
Definition: Triple.cpp:134
TripleTest::elvAngleTest
int elvAngleTest()
Definition: Triple_T.cpp:185
gnsstk::Exception
Definition: Exception.hpp:151
TestUtil.hpp
TripleTest::azAngleTest
int azAngleTest()
Definition: Triple_T.cpp:214
TripleTest::TripleTest
TripleTest()
Definition: Triple_T.cpp:48
TripleTest::magTest
int magTest()
Definition: Triple_T.cpp:104
TripleTest::unitVectorTest
int unitVectorTest()
Definition: Triple_T.cpp:122
std
Definition: Angle.hpp:142
TripleTest::setTest
int setTest()
Definition: Triple_T.cpp:53
gnsstk::Triple::cross
Triple cross(const Triple &right) const noexcept
Definition: Triple.cpp:118
Triple.hpp
TripleTest::crossTest
int crossTest()
Definition: Triple_T.cpp:87
TripleTest
Definition: Triple_T.cpp:45
gnsstk::Triple::azAngle
double azAngle(const Triple &right) const
Definition: Triple.cpp:195
gnsstk::TestUtil
Definition: TestUtil.hpp:265
gnsstk::Triple::mag
double mag() const noexcept
Definition: Triple.cpp:129


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