Angle_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 "Angle.hpp"
42 #include "GNSSconstants.hpp"
43 
44 class Angle_T
45 {
46 public:
47  Angle_T();
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  double tangent)
58  : v(val), t(type), rad(radians), deg(degrees), sin(sine),
59  cos(cosine), sc(semicirc), tan(tangent)
60  {}
61  double v;
63  double rad;
64  double deg;
65  double sc;
66  double sin;
67  double cos;
68  double tan;
69  };
70 };
71 
72 
73 const double Angle_T::epsilon = 1e-9;
74 
77 {
78 }
79 
80 
81 unsigned Angle_T ::
83 {
84  TUDEF("Angle", "Angle");
85  const double radians = 0.52359877559829881566;
86  const double degrees = 30.0;
87  const double semicirc = 0.16666666666666666666;
88  const double sine = ::sin(radians);
89  const double cosine = ::cos(radians);
90  const double tangent = ::tan(radians);
91  // test default constructor
92  gnsstk::Angle uut1;
93  TUASSERTE(bool, true, isnan(uut1.rad()));
94  TUASSERTE(bool, true, isnan(uut1.deg()));
95  TUASSERTE(bool, true, isnan(uut1.semicirc()));
96  TUASSERTE(bool, true, isnan(uut1.sin()));
97  TUASSERTE(bool, true, isnan(uut1.cos()));
98  TUASSERTE(bool, true, isnan(uut1.tan()));
99  // test radians constructor
100  gnsstk::Angle uut2(radians, gnsstk::AngleType::Rad);
101  TUASSERTFEPS(radians, uut2.rad(), epsilon);
102  TUASSERTFEPS(degrees, uut2.deg(), epsilon);
103  TUASSERTFEPS(semicirc,uut2.semicirc(), epsilon);
104  TUASSERTFEPS(sine, uut2.sin(), epsilon);
105  TUASSERTFEPS(cosine, uut2.cos(), epsilon);
106  TUASSERTFEPS(tangent, uut2.tan(), epsilon);
107  // test degrees constructor
108  gnsstk::Angle uut3(degrees, gnsstk::AngleType::Deg);
109  TUASSERTFEPS(radians, uut3.rad(), epsilon);
110  TUASSERTFEPS(degrees, uut3.deg(), epsilon);
111  TUASSERTFEPS(semicirc,uut3.semicirc(), epsilon);
112  TUASSERTFEPS(sine, uut3.sin(), epsilon);
113  TUASSERTFEPS(cosine, uut3.cos(), epsilon);
114  TUASSERTFEPS(tangent, uut3.tan(), epsilon);
115  // test sin constructor
117  TUASSERTFEPS(radians, uut4.rad(), epsilon);
118  TUASSERTFEPS(degrees, uut4.deg(), epsilon);
119  TUASSERTFEPS(semicirc,uut4.semicirc(), epsilon);
120  TUASSERTFEPS(sine, uut4.sin(), epsilon);
121  TUASSERTFEPS(cosine, uut4.cos(), epsilon);
122  TUASSERTFEPS(tangent, uut4.tan(), epsilon);
123  // test cos constructor
125  TUASSERTFEPS(radians, uut5.rad(), epsilon);
126  TUASSERTFEPS(degrees, uut5.deg(), epsilon);
127  TUASSERTFEPS(semicirc,uut5.semicirc(), epsilon);
128  TUASSERTFEPS(sine, uut5.sin(), epsilon);
129  TUASSERTFEPS(cosine, uut5.cos(), epsilon);
130  TUASSERTFEPS(tangent, uut5.tan(), epsilon);
131  // test sin/cos constructor
132  gnsstk::Angle uut6(sine, cosine);
133  TUASSERTFEPS(radians, uut6.rad(), epsilon);
134  TUASSERTFEPS(degrees, uut6.deg(), epsilon);
135  TUASSERTFEPS(semicirc,uut6.semicirc(), epsilon);
136  TUASSERTFEPS(sine, uut6.sin(), epsilon);
137  TUASSERTFEPS(cosine, uut6.cos(), epsilon);
138  TUASSERTFEPS(tangent, uut6.tan(), epsilon);
139  // test semi-circles constructor
141  TUASSERTFEPS(radians, uut7.rad(), epsilon);
142  TUASSERTFEPS(degrees, uut7.deg(), epsilon);
143  TUASSERTFEPS(semicirc,uut7.semicirc(), epsilon);
144  TUASSERTFEPS(sine, uut7.sin(), epsilon);
145  TUASSERTFEPS(cosine, uut7.cos(), epsilon);
146  TUASSERTFEPS(tangent, uut7.tan(), epsilon);
147  TURETURN();
148 }
149 
150 
151 unsigned Angle_T ::
153 {
154  TUDEF("Angle", "setValue");
155  using gnsstk::DEG2RAD;
156  using gnsstk::RAD2DEG;
157  static const TestData testData[] =
158  {
159  { 0.0, gnsstk::AngleType::Rad, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
160  { 1.0, gnsstk::AngleType::Deg, 1.0*DEG2RAD, 1.0, ::sin(1.0*DEG2RAD),
161  ::cos(1.0*DEG2RAD), 1.0/180.0, ::tan(1.0*DEG2RAD) },
162  { 0.34, gnsstk::AngleType::Sin, ::asin(0.34), ::asin(0.34)*RAD2DEG,
163  0.34, ::cos(::asin(0.34)), ::asin(0.34)/gnsstk::PI,
164  ::tan(::asin(0.34)) },
165  { 0.78, gnsstk::AngleType::Cos, ::acos(0.78), ::acos(0.78)*RAD2DEG,
166  ::sin(::acos(0.78)), 0.78, ::acos(0.78)/gnsstk::PI,
167  ::tan(::acos(0.78)) },
168  };
169  unsigned numTests = sizeof(testData) / sizeof(testData[0]);
170  for (unsigned testNum = 0; testNum < numTests; testNum++)
171  {
172  const TestData& td(testData[testNum]);
173  gnsstk::Angle uut;
174  uut.setValue(td.v, td.t);
175  TUASSERTFEPS(td.rad, uut.rad(), epsilon);
176  TUASSERTFEPS(td.deg, uut.deg(), epsilon);
177  TUASSERTFEPS(td.sc, uut.semicirc(), epsilon);
178  TUASSERTFEPS(td.sin, uut.sin(), epsilon);
179  TUASSERTFEPS(td.cos, uut.cos(), epsilon);
180  TUASSERTFEPS(td.tan, uut.tan(), epsilon);
181  }
182  TURETURN();
183 }
184 
185 
186 int main()
187 {
188  unsigned errorTotal = 0;
189  Angle_T testClass;
190 
191  errorTotal += testClass.constructorTest();
192  errorTotal += testClass.setValueTest();
193 
194  std::cout << "Total Failures for " << __FILE__ << ": " << errorTotal
195  << std::endl;
196 
197  return errorTotal;
198 }
gnsstk::AngleType::SemiCircle
@ SemiCircle
Value is in semi-circles (aka half-cycles).
Angle_T::TestData::sc
double sc
Definition: Angle_T.cpp:65
Angle_T::TestData
Definition: Angle_T.cpp:52
gnsstk::DEG2RAD
const double DEG2RAD
Multiply degrees by DEG2RAD to get radians.
Definition: GNSSconstants.hpp:64
gnsstk::Angle::rad
double rad() const
Get the angle in radians.
Definition: Angle.hpp:94
gnsstk::Angle::semicirc
double semicirc() const
Get the angle in semi-circles (aka half-cycles).
Definition: Angle.hpp:102
Angle_T::TestData::t
gnsstk::AngleType t
Definition: Angle_T.cpp:62
gnsstk::Angle::tan
double tan() const
Get the tangent of this angle.
Definition: Angle.hpp:106
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
Angle.hpp
gnsstk::PI
const double PI
GPS value of PI; also specified by GAL.
Definition: GNSSconstants.hpp:62
Angle_T::setValueTest
unsigned setValueTest()
Definition: Angle_T.cpp:152
GNSSconstants.hpp
Angle_T
Definition: Angle_T.cpp:44
gnsstk::Angle
Definition: Angle.hpp:53
std::sin
double sin(gnsstk::Angle x)
Definition: Angle.hpp:144
Angle_T::TestData::cos
double cos
Definition: Angle_T.cpp:67
Angle_T::TestData::rad
double rad
Definition: Angle_T.cpp:63
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
main
int main()
Definition: Angle_T.cpp:186
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
Angle_T::TestData::tan
double tan
Definition: Angle_T.cpp:68
Angle_T::TestData::TestData
TestData(double val, gnsstk::AngleType type, double radians, double degrees, double sine, double cosine, double semicirc, double tangent)
Definition: Angle_T.cpp:55
gnsstk::AngleType::Deg
@ Deg
Value is in degrees.
TUASSERTFEPS
#define TUASSERTFEPS(EXP, GOT, EPS)
Definition: TestUtil.hpp:126
gnsstk::Angle::deg
double deg() const
Get the angle in degrees.
Definition: Angle.hpp:98
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
Angle_T::TestData::sin
double sin
Definition: Angle_T.cpp:66
std::tan
double tan(gnsstk::Angle x)
Definition: Angle.hpp:148
gnsstk::Angle::setValue
void setValue(double v, AngleType t)
Definition: Angle.cpp:68
Angle_T::Angle_T
Angle_T()
Definition: Angle_T.cpp:76
Angle_T::constructorTest
unsigned constructorTest()
Definition: Angle_T.cpp:82
Angle_T::epsilon
static const double epsilon
Definition: Angle_T.cpp:50
Angle_T::TestData::v
double v
Definition: Angle_T.cpp:61
Angle_T::TestData::deg
double deg
Definition: Angle_T.cpp:64


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