AngleReduced_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 <math.h>
40 #include "TestUtil.hpp"
41 #include "AngleReduced.hpp"
42 #include "GNSSconstants.hpp"
43 
45 {
46 public:
48  unsigned constructorTest();
49  unsigned setValueTest();
50  static const double epsilon;
51 
52  class TestData
53  {
54  public:
55  TestData(double val, gnsstk::AngleType type, double radians,
56  double degrees, double sine, double cosine, double semicirc)
57  : v(val), t(type), rad(radians), deg(degrees), sin(sine),
58  cos(cosine), sc(semicirc)
59  {}
60  double v;
62  double rad;
63  double deg;
64  double sc;
65  double sin;
66  double cos;
67  };
68 };
69 
70 
71 const double AngleReduced_T::epsilon = 1e-9;
72 
75 {
76 }
77 
78 
79 unsigned AngleReduced_T ::
81 {
82  TUDEF("AngleReduced", "AngleReduced");
83  const double radians = 0.52359877559829881566;
84  const double degrees = 30.0;
85  const double semicirc = 0.16666666666666666666;
86  const double sine = ::sin(radians);
87  const double cosine = ::cos(radians);
88  // test default constructor
90  TUASSERTE(bool, true, isnan(uut1.sin()));
91  TUASSERTE(bool, true, isnan(uut1.cos()));
92  // test radians constructor
94  TUASSERTFEPS(sine, uut2.sin(), epsilon);
95  TUASSERTFEPS(cosine, uut2.cos(), epsilon);
96  // test degrees constructor
98  TUASSERTFEPS(sine, uut3.sin(), epsilon);
99  TUASSERTFEPS(cosine, uut3.cos(), epsilon);
100  // test sin constructor
102  TUASSERTFEPS(sine, uut4.sin(), epsilon);
103  TUASSERTFEPS(cosine, uut4.cos(), epsilon);
104  // test cos constructor
106  TUASSERTFEPS(sine, uut5.sin(), epsilon);
107  TUASSERTFEPS(cosine, uut5.cos(), epsilon);
108  // test sin/cos constructor
109  gnsstk::AngleReduced uut6(sine, cosine);
110  TUASSERTFEPS(sine, uut6.sin(), epsilon);
111  TUASSERTFEPS(cosine, uut6.cos(), epsilon);
112  // test semi-circles constructor
114  TUASSERTFEPS(sine, uut7.sin(), epsilon);
115  TUASSERTFEPS(cosine, uut7.cos(), epsilon);
116  TURETURN();
117 }
118 
119 
120 unsigned AngleReduced_T ::
122 {
123  TUDEF("AngleReduced", "setValue");
124  using gnsstk::DEG2RAD;
125  using gnsstk::RAD2DEG;
126  static const TestData testData[] =
127  {
128  { 0.0, gnsstk::AngleType::Rad, 0.0, 0.0, 0.0, 1.0, 0.0 },
129  { 1.0, gnsstk::AngleType::Deg, 1.0*DEG2RAD, 1.0,
130  ::sin(1.0*DEG2RAD), ::cos(1.0*DEG2RAD), 1.0/180.0 },
131  { 0.34, gnsstk::AngleType::Sin, ::asin(0.34),
132  ::asin(0.34)*RAD2DEG, 0.34, ::cos(::asin(0.34)),
133  ::asin(0.34)/gnsstk::PI },
134  { 0.78, gnsstk::AngleType::Cos, ::acos(0.78),
135  ::acos(0.78)*RAD2DEG, ::sin(::acos(0.78)), 0.78,
136  ::acos(0.78)/gnsstk::PI },
137  };
138  unsigned numTests = sizeof(testData) / sizeof(testData[0]);
139  for (unsigned testNum = 0; testNum < numTests; testNum++)
140  {
141  const TestData& td(testData[testNum]);
143  uut.setValue(td.v, td.t);
144  TUASSERTFEPS(td.sin, uut.sin(), epsilon);
145  TUASSERTFEPS(td.cos, uut.cos(), epsilon);
146  }
147  TURETURN();
148 }
149 
150 
151 int main()
152 {
153  unsigned errorTotal = 0;
154  AngleReduced_T testClass;
155 
156  errorTotal += testClass.constructorTest();
157  errorTotal += testClass.setValueTest();
158 
159  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
160  << std::endl;
161 
162  return errorTotal;
163 }
gnsstk::AngleType::SemiCircle
@ SemiCircle
Value is in semi-circles (aka half-cycles).
gnsstk::AngleReduced
Definition: AngleReduced.hpp:60
gnsstk::DEG2RAD
const double DEG2RAD
Multiply degrees by DEG2RAD to get radians.
Definition: GNSSconstants.hpp:64
AngleReduced_T::TestData::TestData
TestData(double val, gnsstk::AngleType type, double radians, double degrees, double sine, double cosine, double semicirc)
Definition: AngleReduced_T.cpp:55
AngleReduced_T::constructorTest
unsigned constructorTest()
Definition: AngleReduced_T.cpp:80
AngleReduced_T::TestData::v
double v
Definition: AngleReduced_T.cpp:60
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::AngleReduced::sin
double sin() const
Get the sine of this angle.
Definition: AngleReduced.hpp:94
AngleReduced_T::TestData::sin
double sin
Definition: AngleReduced_T.cpp:65
AngleReduced_T::epsilon
static const double epsilon
Definition: AngleReduced_T.cpp:50
gnsstk::PI
const double PI
GPS value of PI; also specified by GAL.
Definition: GNSSconstants.hpp:62
GNSSconstants.hpp
AngleReduced_T::TestData::sc
double sc
Definition: AngleReduced_T.cpp:64
AngleReduced_T::TestData
Definition: AngleReduced_T.cpp:52
std::sin
double sin(gnsstk::Angle x)
Definition: Angle.hpp:144
gnsstk::AngleReduced::setValue
void setValue(double v, AngleType t)
Definition: AngleReduced.cpp:53
main
int main()
Definition: AngleReduced_T.cpp:151
AngleReduced_T::TestData::cos
double cos
Definition: AngleReduced_T.cpp:66
gnsstk::AngleType::Rad
@ Rad
Value is in radians.
gnsstk::RAD2DEG
const double RAD2DEG
Multiply radians by RAD2DEG to get degrees.
Definition: GNSSconstants.hpp:66
gnsstk::AngleType::Sin
@ Sin
Value is the sine of the angle.
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::AngleType::Cos
@ Cos
Value is the cosine of the angle.
gnsstk::AngleReduced::cos
double cos() const
Get the cosine of this angle.
Definition: AngleReduced.hpp:98
gnsstk::AngleType::Deg
@ Deg
Value is in degrees.
TUASSERTFEPS
#define TUASSERTFEPS(EXP, GOT, EPS)
Definition: TestUtil.hpp:126
AngleReduced_T::AngleReduced_T
AngleReduced_T()
Definition: AngleReduced_T.cpp:74
AngleReduced_T
Definition: AngleReduced_T.cpp:44
gnsstk::AngleType
AngleType
Definition: AngleType.hpp:54
std::cos
double cos(gnsstk::Angle x)
Definition: Angle.hpp:146
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
AngleReduced_T::TestData::t
gnsstk::AngleType t
Definition: AngleReduced_T.cpp:61
AngleReduced_T::setValueTest
unsigned setValueTest()
Definition: AngleReduced_T.cpp:121
AngleReduced_T::TestData::rad
double rad
Definition: AngleReduced_T.cpp:62
AngleReduced_T::TestData::deg
double deg
Definition: AngleReduced_T.cpp:63
AngleReduced.hpp


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